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

# Anthropic 格式转换器

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

## 概述

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

## 配置方法

### SDK 配置

将 base URL 设置为：

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

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

### cURL / 直接 API 调用

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

```
https://api.pipellm.ai/anthropic/v1/messages
```

## 使用示例

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
    import anthropic

    client = anthropic.Anthropic(
        api_key="your-pipellm-api-key",
        base_url="https://api.pipellm.ai/anthropic"
    )

    message = client.messages.create(
        model="gemini-2.0-flash",  # 或 "gpt-4o"
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "你好，今天怎么样？"}
        ]
    )

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

  <Tab title="TypeScript SDK">
    ```typescript theme={null}
    import Anthropic from "@anthropic-ai/sdk";

    const client = new Anthropic({
      apiKey: "your-pipellm-api-key",
      baseURL: "https://api.pipellm.ai/anthropic",
    });

    const message = await client.messages.create({
      model: "gemini-2.0-flash", // 或 'gpt-4o'
      max_tokens: 1024,
      messages: [{ role: "user", content: "你好，今天怎么样？" }],
    });

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

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

## 支持的模型

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

| 供应商    | 示例模型                                 |
| ------ | ------------------------------------ |
| Gemini | `gemini-2.0-flash`, `gemini-1.5-pro` |
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `o1`        |

## 功能支持

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