> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jiji.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini

> 使用 Gemini 原生 generateContent 格式调用 Gemini 模型。

```text theme={null}
POST https://www.jiji.cc/v1beta/models/{model}:generateContent
POST https://www.jiji.cc/v1beta/models/{model}:streamGenerateContent?alt=sse
```

兼容 Google Gemini API 原生格式，Gemini CLI 使用的就是这个接口。把 `{model}` 换成模型 ID，可用的 Gemini 模型以 [模型广场](https://www.jiji.cc/extension/models) 为准。

## 基础调用

<CodeGroup>
  ```python Python theme={null}
  import os
  from google import genai
  from google.genai import types

  client = genai.Client(
      api_key=os.environ["JIJI_API_KEY"],
      http_options=types.HttpOptions(base_url="https://www.jiji.cc"),
  )

  resp = client.models.generate_content(
      model="your-gemini-model",
      contents="用一句话解释什么是闭包。",
  )
  print(resp.text)
  ```

  ```bash cURL theme={null}
  curl "https://www.jiji.cc/v1beta/models/your-gemini-model:generateContent" \
    -H "Content-Type: application/json" \
    -H "x-goog-api-key: $JIJI_API_KEY" \
    -d '{
      "contents": [{"parts": [{"text": "用一句话解释什么是闭包。"}]}]
    }'
  ```
</CodeGroup>

<Note>
  把 `your-gemini-model` 替换为模型广场中的 Gemini 模型 ID。Python 需要先安装 SDK：`pip install google-genai`。
</Note>

## 流式输出

```python Python theme={null}
for chunk in client.models.generate_content_stream(
    model="your-gemini-model",
    contents="写一首关于春天的短诗",
):
    print(chunk.text, end="", flush=True)
```

## 系统提示词和参数

```python Python theme={null}
resp = client.models.generate_content(
    model="your-gemini-model",
    contents="介绍一下你自己",
    config=types.GenerateContentConfig(
        system_instruction="你是一个简洁的编程助手。",
        temperature=0.7,
        max_output_tokens=1024,
    ),
)
print(resp.text)
```

## 多轮对话

```python Python theme={null}
chat = client.chats.create(model="your-gemini-model")
print(chat.send_message("我叫小明").text)
print(chat.send_message("我叫什么名字？").text)
```

## 图片理解

```python Python theme={null}
with open("photo.png", "rb") as f:
    image_bytes = f.read()

resp = client.models.generate_content(
    model="your-gemini-model",
    contents=[
        types.Part.from_bytes(data=image_bytes, mime_type="image/png"),
        "这张图片里有什么？",
    ],
)
print(resp.text)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.