# API 概览

> LLMoxy API 的 Base URL、鉴权方式与 Python、Node.js、curl 快速接入示例。

LLMoxy 提供完全兼容的 Anthropic Messages API 接口，只需更改 Base URL 即可使用官方 SDK 无缝接入。

## Base URL

```txt
https://llmoxy.com/v1
```

> **TIP**
> Claude Code 等工具使用的地址 **不带** `/v1`，即 `https://llmoxy.com`。SDK 调用时带 `/v1`。

## 鉴权方式

### 方式一：x-api-key（推荐）

```http
x-api-key: YOUR_API_KEY
```

### 方式二：Authorization

```http
Authorization: Bearer YOUR_API_KEY
```

## 快速体验

### Python

```python
from anthropic import Anthropic

client = Anthropic(
api_key="YOUR_API_KEY",
base_url="https://llmoxy.com/v1"
)

message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "你好！"}
]
)

print(message.content[0].text)
```

### Node.js

```js
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://llmoxy.com/v1'
});

const message = await client.messages.create({
model: 'claude-opus-5-5',
max_tokens: 1024,
messages: [
{ role: 'user', content: '你好！' }
]
});

console.log(message.content[0].text);
```

### OpenAI 兼容（Chat Completions）

#### curl

```bash
curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "messages": [
      { "role": "user", "content": "Say hello in one short sentence." }
    ]
  }'
```

#### TypeScript

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.LLMOXY_API_KEY,
  baseURL: "https://llmoxy.com/v1",
});

const response = await client.chat.completions.create({
  model: "grok-4.7",
  messages: [{ role: "user", content: "Write a haiku about routers." }],
});

console.log(response.choices[0]?.message?.content);
```

#### Python

```py
from openai import OpenAI

client = OpenAI(
    api_key="<LLMOXY_API_KEY>",
    base_url="https://llmoxy.com/v1",
)

response = client.chat.completions.create(
    model="grok-4.7",
    messages=[{"role": "user", "content": "Write a haiku about routers."}],
)

print(response.choices[0].message.content)
```

## 流式输出

在 Chat 或 Responses 请求中设置 `stream: true`，LLMoxy 会返回 OpenAI 兼容的 SSE 流。

```bash
curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "stream": true,
    "messages": [
      { "role": "user", "content": "Count from one to five." }
    ]
  }'
```

## 支持的模型

### Claude 系列（可用分组：Claude）

| 模型 | 说明 |
| --- | --- |
| claude-fable-5-2 | 最强性能 |
| claude-opus-5-5 | 均衡之选 |

### Gemini 系列（可用分组：Gemini）

| 模型 | 说明 |
| --- | --- |
| gemini-4-argon | 最强性能 |
| gemini-3.8-flash | 快速响应 |

> **最新模型列表**
> 具体可用模型以 [官网模型广场](https://llmoxy.com/) 为准。

## 计费方式

按实际 Token 用量计费（含缓存写入和缓存读取），不同模型价格不同。详见 [分组与计价](https://llmoxy.com/docs/get-started/recharge-and-pricing)。

## 下一步

- [Anthropic 格式详细文档](https://llmoxy.com/docs/api-reference/anthropic-format) — 请求参数、响应格式、代码示例
- [Chat Completions](https://llmoxy.com/docs/api-reference/chat-completions) — OpenAI 兼容请求格式
- [路由、计费与错误](https://llmoxy.com/docs/api-reference/routing-billing-errors) — 了解费用和错误码

本文是 https://llmoxy.com/docs/api-reference/api-overview 的 markdown 版本。
