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

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

### cURL / 直接 API 调用

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

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

## 使用示例

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
    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-2.0-flash",  # 或 "claude-sonnet-4-20250514"
        messages=[
            {"role": "user", "content": "你好，今天怎么样？"}
        ]
    )

    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="TypeScript SDK">
    ```typescript theme={null}
    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-2.0-flash", // 或 'claude-sonnet-4-20250514'
      messages: [{ role: "user", content: "你好，今天怎么样？" }],
    });

    console.log(response.choices[0].message.content);
    ```
  </Tab>

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

## 支持的模型

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

| 供应商       | 示例模型                                                  |
| --------- | ----------------------------------------------------- |
| Gemini    | `gemini-2.0-flash`, `gemini-1.5-pro`                  |
| Anthropic | `claude-sonnet-4-20250514`, `claude-3-5-haiku-latest` |

## 功能支持

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