✅ 服务运行正常

Cursor2API已成功启动并运行中

📍 服务地址

{{BASE_URL}}

🔑 API密钥

0000 (默认)

🎯 兼容性

OpenAI API 标准

🌊 流式支持

支持 SSE 流式响应

🧰 Tool Calls

支持 tools / tool_choice / tool_calls

🧠 Thinking

自动暴露 -thinking 模型(thinking 不对外透出)

🚀 快速开始

# 获取模型列表 curl -H "Authorization: Bearer YOUR_KEY" {{BASE_URL}}/v1/models

非流式聊天 (Non-Streaming)

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "Hello!"}], "stream": false }'

流式聊天 (Streaming)

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "Hello!"}], "stream": true }'

工具调用 (Tool Calls)

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "What is 2+2? Use the calculator tool."}], "tools": [ { "type": "function", "function": { "name": "calculator", "description": "Evaluate a simple arithmetic expression.", "parameters": { "type": "object", "properties": { "expression": {"type": "string"} }, "required": ["expression"] } } } ], "tool_choice": {"type": "function", "function": {"name": "calculator"}}, "stream": false }'

Kilo Code 兼容(可选)

# 当上层强制“必须用工具”时,可在 .env 开启 KILO_TOOL_STRICT=true # 非流式请求:若要求用工具但本轮未产出 tool_calls,会自动重试 1 次(流式不重试)

🤖 支持的AI模型

点击模型卡片可查看详细信息和使用示例

anthropic/gemini-3-flash
Anthropic · Base
anthropic/gemini-3-flash-thinking
Anthropic · Thinking
claude-sonnet-4-5-20250929
Anthropic · Base
claude-sonnet-4-5-20250929-thinking
Anthropic · Thinking
claude-sonnet-4-20250514
Anthropic · Base
claude-sonnet-4-20250514-thinking
Anthropic · Thinking
claude-3-5-sonnet-20241022
Anthropic · Base
claude-3-5-sonnet-20241022-thinking
Anthropic · Thinking

📡 API端点文档

GET
/health

健康检查端点,用于确认服务是否正常运行

curl {{BASE_URL}}/health # 返回示例: {"status":"ok","timestamp":1775230770}
GET
/v1/models

获取所有可用的AI模型列表(需要认证)

curl -H "Authorization: Bearer YOUR_KEY" {{BASE_URL}}/v1/models # 返回示例: { "object": "list", "data": [ { "id": "gemini-3-flash", "object": "model", "created": 1775230811, "owned_by": "cursor2api", "max_tokens": 100000, "context_window": 100000 } ] }
POST
/v1/chat/completions

创建聊天完成请求,支持流式、非流式和 OpenAI 兼容 tool_calls

请求参数

参数类型必填说明
modelstring模型ID
messagesarray消息列表,支持 system/user/assistant/tool 角色
streamboolean是否使用 SSE 流式响应,默认 false
temperaturenumber采样温度,范围 0~2
max_tokensinteger最大生成 token 数,超出则自动截断为模型上限
top_pnumber核采样参数
stoparray停止词序列
userstring终端用户标识符
toolsarray工具定义列表,格式与 OpenAI 一致
tool_choicestring|object"auto" / "none" / "required" / 指定函数对象
presence_penaltynumber存在惩罚,-2.0 ~ 2.0,鼓励谈论新话题
frequency_penaltynumber频率惩罚,-2.0 ~ 2.0,降低重复内容
response_formatobject响应格式,支持 {"type":"json_object"} 强制 JSON 输出
seedinteger随机种子,相同 seed + 相同输入可复现结果
logit_biasobjectToken 级偏差映射,token_id → bias (-100 ~ 100)
logprobsboolean是否返回 token 概率
top_logprobsinteger返回 top K 个 token 的概率
ninteger生成几份回复,默认 1
parallel_tool_callsboolean是否允许并行调用多个工具,默认 true

基础示例(非流式)

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "你好"}], "stream": false }' # 返回示例: { "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1775230770, "model": "gemini-3-flash", "choices": [{ "index": 0, "message": {"role": "assistant", "content": "你好!有什么可以帮你的?"}, "finish_reason": "stop" }], "usage": {"prompt_tokens": 10, "completion_tokens": 8, "total_tokens": 18} }

流式示例

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "你好"}], "stream": true }' # 返回格式为 SSE: data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1775230770,"model":"gemini-3-flash","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1775230770,"model":"gemini-3-flash","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]} data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1775230770,"model":"gemini-3-flash","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: [DONE]

工具调用(Tool Calls)

curl -X POST {{BASE_URL}}/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_KEY" \ -d '{ "model": "gemini-3-flash", "messages": [{"role": "user", "content": "2+2等于几?使用计算器工具"}], "tools": [{ "type": "function", "function": { "name": "calculator", "description": "执行算术运算", "parameters": { "type": "object", "properties": { "expression": {"type": "string"} }, "required": ["expression"] } } }], "tool_choice": "auto" }' # 非流式返回包含 tool_calls: { "choices": [{ "message": { "role": "assistant", "content": null, "tool_calls": [{ "id": "call_xxx", "type": "function", "function": {"name": "calculator", "arguments": "{\"expression\":\"2+2\"}"} }] }, "finish_reason": "tool_calls" }] }

💡 当响应包含工具调用时,非流式会返回 message.tool_callsfinish_reason="tool_calls"; 流式会在 delta.tool_calls 中逐步输出,最后以 finish_reason="tool_calls" 结束。

POST
错误响应格式

所有错误均以标准 JSON 格式返回

# 认证失败 (401) {"error":{"message":"Invalid API key","type":"authentication_error","code":"invalid_api_key"}} # 参数错误 (400) {"error":{"message":"Invalid model: unknown","type":"invalid_request_error","code":"model_not_found"}} # 服务器错误 (502) {"error":{"message":"Internal server error","type":"internal_error","code":""}}