Responses API
POST https://api.uberllm.dev/v1/responses 在目录中的每个聊天模型上提供 OpenAI 的 Responses API。可以通过 OpenAI SDK (client.responses.create)、Codex CLI 或任何具有“Responses”模式的应用程序使用它。请求会经过与 /v1/chat/completions 相同的路由、重试、密钥限制和计费,并且每次调用都会在 Dashboard → Activity 中列出其费用。
curl https://api.uberllm.dev/v1/responses \
-H "Authorization: Bearer $UBERLLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4.1-flash",
"instructions": "Answer in one short sentence.",
"input": "What is the capital of France?"
}'
from openai import OpenAI
client = OpenAI(base_url="https://api.uberllm.dev/v1", api_key="ull_...")
r = client.responses.create(model="deepseek/deepseek-v4.1-flash", input="Say hi")
print(r.output_text)
无状态存储
UberLLM 不会为您保留响应,以便您稍后继续。每次回复都有
"store": false,并且您在每次调用时都会在 input 中发送整个对话:包括之前的用户消息、模型的
输出项以及您的工具结果。Codex CLI 已经以这种方式工作。
以下内容将被 400 (code: unsupported_parameter) 拒绝,并指出相关字段:
previous_response_id和conversationbackground: true- 类型为
item_reference的 input items - 存储的 prompt templates (
prompt)
GET /v1/responses/{id} 和其他存储响应的 routes 不存在。
请求
| 字段 | 作用 |
|---|---|
model |
任何聊天模型 ID、别名或 :floor / :nitro 后缀,与 chat completions 中相同。 |
input |
一个字符串,或一个项目列表(见下文)。 |
instructions |
作为 system message 发送给模型。 |
stream |
true 用于 server-sent events。 |
max_output_tokens |
输出上限。 |
temperature, top_p, seed, stop |
传递给模型。 |
tools, tool_choice, parallel_tool_calls |
参见下文的 Tools。 |
reasoning.effort |
作为模型的推理工作(会思考的模型)传递。 |
text.format |
text、json_object 或 json_schema (结构化输出)。 |
metadata |
您自己的标签,显示在 Activity 行上,与 chat completions 中相同。 |
provider, models |
UberLLM 路由选项,与 chat completions 中相同 (Models & routing)。 |
store, include, prompt_cache_key, service_tier, truncation |
已接受但未使用。始终返回加密的推理。 |
输入项
| 项目 | 变为 |
|---|---|
message 角色为 user、assistant、system 或 developer |
一条聊天消息。developer 作为 system 发送。内容部分 input_text、output_text、input_image (image_url: 一个 https 或 data: URL) 和 input_file (file_data 或 file_url)。 |
function_call |
助手的工具调用,按顺序保留。 |
function_call_output |
工具的结果。输出中的图片在下一个用户回合中发送。 |
custom_tool_call, custom_tool_call_output |
对自定义(自由形式)工具的调用及其结果。 |
reasoning |
模型之前的推理,在下一个回合中返回给模型。 |
web_search_call 和其他托管工具记录 |
跳过。 |
项目 id 已接受但被忽略。file_id (上传文件)在 input_image / input_file 中不支持:请以内联方式或通过 URL 发送文件。
工具
function:{"type": "function", "name", "description", "parameters", "strict"}。 模型的调用返回一个function_call项,包含call_id、name和arguments(一个 JSON 字符串)。回复一个function_call_output项,携带相同的call_id。custom(自由格式输入,例如 Codex 的apply_patch):模型会获得 该工具,附带一个字符串输入,以及format.definition中的语法作为其 描述。调用返回一个custom_tool_call项,包含原始input。namespace(Codex 的 MCP 工具):内部的每个工具都会在其命名空间和名称合并后(mcp__github__get_issue)提供给模型; 调用返回时,name和namespace会再次分开。- 托管工具(
web_search、file_search、code_interpreter、image_generation、computer_use、mcp)在 OpenAI 自己的服务器上运行。它们不包含在请求中,模型在没有它们的情况下进行回答。
tool_choice 接受 "auto"、"none"、"required" 或
{"type": "function", "name": "…"}。
响应
{
"id": "resp_…",
"object": "response",
"created_at": 1793333237,
"status": "completed",
"model": "deepseek/deepseek-v4.1-flash",
"output": [
{"type": "reasoning", "id": "rs_…", "summary": [],
"content": [{"type": "reasoning_text", "text": "…"}], "encrypted_content": "ull1:…"},
{"type": "message", "id": "msg_…", "status": "completed", "role": "assistant",
"content": [{"type": "output_text", "text": "Paris.", "annotations": []}]},
{"type": "function_call", "id": "fc_…", "status": "completed",
"call_id": "call_…", "name": "get_weather", "arguments": "{\"city\":\"Paris\"}"}
],
"usage": {
"input_tokens": 43, "input_tokens_details": {"cached_tokens": 0},
"output_tokens": 23, "output_tokens_details": {"reasoning_tokens": 0},
"total_tokens": 66, "cost_usd": 0.0000184
},
"store": false
}
- 当模型返回其推理时,会出现一个
reasoning项。在下一个input中按原样发送它:encrypted_content包含推理,因此在下一轮中需要它的模型可以获取它。 status在答案达到max_output_tokens(incomplete_details.reason: "max_output_tokens") 或内容过滤器 ("content_filter") 时为incomplete。usage.cost_usd是本次调用的计费金额。非 streaming 响应也会在X-UberLLM-Cost-USDheader 中携带它,并且每个响应都有X-Request-Id,即其 Activity 行的 ID。- 您发送的设置 (
instructions,tools,temperature,max_output_tokens…) 会像 OpenAI 那样被回显。
流式传输
使用 "stream": true,响应以服务器发送事件的形式返回,每个事件都包含 type 和一个从 0 开始的 sequence_number:
response.created,response.in_progress- 对于每个输出项:
response.output_item.added,然后是其增量,然后是包含完成项的response.output_item.done:- 文本:
response.content_part.added,response.output_text.delta…,response.output_text.done,response.content_part.done - 推理:
response.reasoning_text.delta…,response.reasoning_text.done - 函数调用:
response.function_call_arguments.delta…,response.function_call_arguments.done - 自定义工具调用:
response.custom_tool_call_input.done
- 文本:
response.completed(或response.incomplete),包含整个响应及其usage,包括cost_usd。
当慢速模型启动时,: ping 条注释行保持连接开放。每个 SSE 客户端都会跳过它们。
错误
在流开始前被拒绝的请求会收到 HTTP 状态码和 OpenAI 的错误封装,与聊天补全相同 (401, 402 信用额度不足, 404 未知模型, 429; 参见 错误)。如果流开始后出现故障,它会以 response.failed 结束,其中 response.error 包含 code 和 message。在模型完成前停止的流也会以 response.failed 结束,绝不会以 response.completed 结束,因此客户端会重试,而不是保留一半的答案。