$OPENPAI_API_KEY 替换为你的密钥即可执行。
普通对话
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": "解释什么是函数调用"}
]
}'
流式响应
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
}'
视觉输入
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"}}
]
}]
}'
工具调用
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 结构化输出
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 原生协议
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 思考模式
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 原生协议
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
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
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
}'
图像生成
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
}'
文本转语音
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
语音转文字
curl https://openp.ai/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENPAI_API_KEY" \
-F [email protected] \
-F model=whisper-1
模型列表
curl https://openp.ai/v1/models \
-H "Authorization: Bearer $OPENPAI_API_KEY"
账户余额
curl https://openp.ai/v1/dashboard/billing/subscription \
-H "Authorization: Bearer $OPENPAI_API_KEY"