# 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://tw.llmoxy.com/docs/get-started/recharge-and-pricing)。

## 下一步

- [Anthropic 格式詳細文件](https://tw.llmoxy.com/docs/api-reference/anthropic-format) — 請求參數、響應格式、程式碼範例
- [Chat Completions](https://tw.llmoxy.com/docs/api-reference/chat-completions) — OpenAI 相容請求格式
- [路由、計費與錯誤](https://tw.llmoxy.com/docs/api-reference/routing-billing-errors) — 了解費用和錯誤碼

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