> ## 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.

# OpenAI 格式转换器

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

## 概述

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

## 配置方法

### SDK 配置

将 base URL 设置为：

```
https://api.pipellm.ai/openai/v1
```

> [!NOTE]
>
> SDK 会自动添加 `/chat/completions`，所以你只需要将 base URL 设置为
> `/openai/v1`。

### cURL / 直接 API 调用

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

```
https://api.pipellm.ai/openai/v1/chat/completions
```

## 使用示例

> [tab] Python SDK
>
> ```python theme={"dark"}
> from openai import OpenAI
>
> client = OpenAI(
>     api_key="your-pipellm-api-key",
>     base_url="https://api.pipellm.ai/openai/v1"
> )
>
> response = client.chat.completions.create(
>     model="gemini-3-flash-preview",  # 或 "claude-sonnet-4-6"
>     messages=[
>         {"role": "user", "content": "你好，今天怎么样？"}
>     ]
> )
>
> print(response.choices[0].message.content)
> ```

> [tab] TypeScript SDK
>
> ```typescript theme={"dark"}
> import OpenAI from "openai";
>
> const client = new OpenAI({
>   apiKey: "your-pipellm-api-key",
>   baseURL: "https://api.pipellm.ai/openai/v1",
> });
>
> const response = await client.chat.completions.create({
>   model: "gemini-3-flash-preview", // 或 'claude-sonnet-4-6'
>   messages: [{ role: "user", content: "你好，今天怎么样？" }],
> });
>
> console.log(response.choices[0].message.content);
> ```

> [tab] cURL
>
> ```bash theme={"dark"}
> curl https://api.pipellm.ai/openai/v1/chat/completions \
>   -H "Content-Type: application/json" \
>   -H "Authorization: Bearer your-pipellm-api-key" \
>   -d '{
>     "model": "gemini-3-flash-preview",
>     "messages": [
>       {"role": "user", "content": "你好，今天怎么样？"}
>     ]
>   }'
> ```

## 支持的模型

你可以使用 PipeLLM 上任何 Gemini 或 Anthropic 模型，并以 OpenAI 格式调用：

| 供应商 | 示例模型 |
| - | - |
| Gemini | `gemini-3-flash-preview` |
| Anthropic | `claude-sonnet-4-6` |

## 功能支持

| 功能 | 状态 |
| - | - |
| 流式输出 | ✅ 支持 |
| 工具调用 | ✅ 支持 |
| 图像识别 | ✅ 支持 |
| 系统提示词 | ✅ 支持 |
| 思考 | ✅ 支持 |

## Gemini 3 思考与 Thought Signature

Gemini 3 模型会在函数调用 part 上返回 `thoughtSignature`；如果同一回合的下一次请求
没有在原 part 上带回该签名，模型会返回 `400`。这是模型的原生要求，详见 Google 官方的
[Thought signatures](https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures) 文档。

> [!WARNING]
>
> Chat Completions 格式没有按工具调用携带签名的字段，本转换器也不会回放签名。
> 响应只会把第一个签名放在非标准的顶层 `thought_signature` 字段中；你在 `messages`
> 里回传的 `tool_calls` 到达 Gemini 时不带签名。因此在 Gemini 3 模型上使用函数调用、
> 回传工具结果时可能失败。Gemini 3 的工具调用建议优先使用
> [Gemini 原生路由](https://docs.pipellm.ai/zh/api-reference/gemini/overview)，或按函数调用回放签名的
> [Responses 格式](https://docs.pipellm.ai/zh/converter/responses-format.md#思考与签名)。

Gemini 3 的普通对话、流式输出和 `reasoning_content` 输出不受影响。对 Gemini 2.5 模型，
回传签名是可选的。

### 思考等级

Gemini 3 目标的 `reasoning_effort`（`low`、`medium`、`high`）映射为 `generationConfig.thinkingConfig.thinkingLevel`。若同时提供扩展字段 `max_reasoning_tokens`，以该字段为准，并转换为思考等级，而不是精确 token 预算。Gemini 2.5 使用数值型 `thinkingBudget`；具体等级仍须由目标模型支持。


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