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

# cURL 示例集

> 常见任务的 cURL 模板,可直接复制粘贴

把以下示例中的 `$OPENPAI_API_KEY` 替换为你的密钥即可执行。

## 普通对话

```bash theme={null}
curl https://openp.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [
      {"role": "system", "content": "你是中文助手"},
      {"role": "user", "content": "解释什么是函数调用"}
    ]
  }'
```

## 流式响应

```bash theme={null}
curl -N https://openp.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role": "user", "content": "讲个 100 字故事"}],
    "stream": true
  }'
```

## 视觉输入

```bash theme={null}
curl https://openp.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "图里有什么?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
      ]
    }]
  }'
```

## 工具调用

```bash theme={null}
curl https://openp.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role": "user", "content": "上海今天的天气"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather for a city",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }]
  }'
```

## JSON 结构化输出

```bash theme={null}
curl https://openp.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role": "user", "content": "返回一个 user JSON,包含 name 与 age"}],
    "response_format": {"type": "json_object"}
  }'
```

## Claude 原生协议

```bash theme={null}
curl https://openp.ai/v1/messages \
  -H "x-api-key: $OPENPAI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-8",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "hello"}]
  }'
```

## Claude 思考模式

```bash theme={null}
curl https://openp.ai/v1/messages \
  -H "x-api-key: $OPENPAI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-8",
    "max_tokens": 4096,
    "thinking": {"type": "enabled", "budget_tokens": 8000},
    "messages": [{"role": "user", "content": "证明哥德巴赫猜想"}]
  }'
```

## Gemini 原生协议

```bash theme={null}
curl "https://openp.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "hello"}]}]
  }'
```

## Embeddings

```bash theme={null}
curl https://openp.ai/v1/embeddings \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": ["hello", "world"]
  }'
```

## Rerank

```bash theme={null}
curl https://openp.ai/v1/rerank \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-multilingual-v3.0",
    "query": "什么是向量数据库?",
    "documents": ["FAISS 是向量检索库", "Postgres 是关系库"],
    "top_n": 1
  }'
```

## 图像生成

```bash theme={null}
curl https://openp.ai/v1/images/generations \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "A red panda eating bamboo, watercolor style",
    "size": "1024x1024",
    "n": 1
  }'
```

## 文本转语音

```bash theme={null}
curl https://openp.ai/v1/audio/speech \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "Hello from OpenPAI",
    "voice": "alloy"
  }' \
  --output speech.mp3
```

## 语音转文字

```bash theme={null}
curl https://openp.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -F file=@audio.mp3 \
  -F model=whisper-1
```

## 模型列表

```bash theme={null}
curl https://openp.ai/v1/models \
  -H "Authorization: Bearer $OPENPAI_API_KEY"
```

## 账户余额

```bash theme={null}
curl https://openp.ai/v1/dashboard/billing/subscription \
  -H "Authorization: Bearer $OPENPAI_API_KEY"
```
