> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arouter.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# cURL

> 使用 cURL 进行快速测试和脚本编写。

## OpenAI 兼容端点

```bash theme={null}
curl https://api.arouter.ai/v1/chat/completions \
  -H "Authorization: Bearer lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

### 切换 Provider

```bash theme={null}
# 通过 OpenAI 兼容端点使用 Anthropic
curl https://api.arouter.ai/v1/chat/completions \
  -H "Authorization: Bearer lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

### 流式输出

```bash theme={null}
curl https://api.arouter.ai/v1/chat/completions \
  -H "Authorization: Bearer lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "openai/gpt-5.4",
    "messages": [{"role": "user", "content": "写一首诗。"}],
    "stream": true
  }'
```

<Tip>
  `-N` 标志可禁用输出缓冲，让您实时看到生成的 token。
</Tip>

## Anthropic 原生端点

```bash theme={null}
curl https://api.arouter.ai/v1/messages \
  -H "X-Api-Key: lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

## Gemini 原生端点

```bash theme={null}
curl "https://api.arouter.ai/v1beta/models/gemini-2.5-flash:generateContent?key=lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Hello!"}]}]
  }'
```

## 列出模型

```bash theme={null}
curl https://api.arouter.ai/v1/models \
  -H "Authorization: Bearer lr_live_xxxx"
```

## 嵌入向量

```bash theme={null}
curl https://api.arouter.ai/v1/embeddings \
  -H "Authorization: Bearer lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/text-embedding-3-small",
    "input": "The quick brown fox"
  }'
```

## Key 管理

使用管理密钥（`lr_mgmt_`）管理 API key。

### 创建 API Key

```bash theme={null}
curl -X POST https://api.arouter.ai/api/v1/keys \
  -H "Authorization: Bearer lr_mgmt_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "backend-service",
    "allowed_providers": ["openai", "anthropic"],
    "limit": 150,
    "limit_reset": "monthly"
  }'
```

### 列出 API Key

```bash theme={null}
curl https://api.arouter.ai/api/v1/keys \
  -H "Authorization: Bearer lr_mgmt_xxxx"
```

### 更新 API Key

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/KEY_HASH \
  -H "Authorization: Bearer lr_mgmt_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"disabled": true}'
```

### 删除 API Key

```bash theme={null}
curl -X DELETE https://api.arouter.ai/api/v1/keys/KEY_HASH \
  -H "Authorization: Bearer lr_mgmt_xxxx"
```
