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

# Gemini 格式转换器

> 使用 Gemini SDK 调用 OpenAI 和 Anthropic 模型

## 概述

Gemini 格式转换器允许您使用 Gemini SDK 和 API 格式调用 **OpenAI** 和 **Anthropic** 模型。当您已有使用 Gemini SDK 的代码，但想访问其他供应商的模型时，这非常有用。

## 配置

### SDK 配置

将 base URL 设置为：

```
https://api.pipellm.ai/gemini
```

<Note>SDK 会自动附加模型路径，因此您只需将 base URL 设置为 `/gemini`。</Note>

### cURL / 直接 API 调用

对于直接 API 调用，使用完整端点：

```
https://api.pipellm.ai/gemini/v1beta/models/{model}:generateContent
https://api.pipellm.ai/gemini/v1beta/models/{model}:streamGenerateContent
```

## 使用示例

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
    import google.generativeai as genai
    from google.generativeai import types

    # 使用 PipeLLM 配置
    genai.configure(
        api_key="your-pipellm-api-key",
        transport="rest",
        client_options={"api_endpoint": "api.pipellm.ai/gemini"}
    )

    # 使用 OpenAI 或 Anthropic 模型
    model = genai.GenerativeModel("gpt-4o")  # 或 "claude-sonnet-4-20250514"

    response = model.generate_content("你好，最近怎么样？")
    print(response.text)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.pipellm.ai/gemini/v1beta/models/gpt-4o:generateContent" \
      -H "Content-Type: application/json" \
      -H "x-goog-api-key: your-pipellm-api-key" \
      -d '{
        "contents": [
          {"role": "user", "parts": [{"text": "你好，最近怎么样？"}]}
        ]
      }'
    ```
  </Tab>

  <Tab title="流式输出 (cURL)">
    ```bash theme={null}
    curl "https://api.pipellm.ai/gemini/v1beta/models/claude-sonnet-4-20250514:streamGenerateContent?alt=sse" \
      -H "Content-Type: application/json" \
      -H "x-goog-api-key: your-pipellm-api-key" \
      -d '{
        "contents": [
          {"role": "user", "parts": [{"text": "给我讲个故事"}]}
        ]
      }'
    ```
  </Tab>
</Tabs>

## 支持的模型

您可以使用 PipeLLM 上所有可用的 OpenAI 或 Anthropic 模型：

| 供应商       | 示例模型                                                  |
| --------- | ----------------------------------------------------- |
| OpenAI    | `gpt-4o`, `gpt-4o-mini`, `o1`                         |
| Anthropic | `claude-sonnet-4-20250514`, `claude-3-5-haiku-latest` |

## 功能支持

| 功能   | 状态   |
| ---- | ---- |
| 流式输出 | ✅ 支持 |
| 工具调用 | ✅ 支持 |
| 视觉   | ✅ 支持 |
| 系统提示 | ✅ 支持 |
| 思考   | ✅ 支持 |
