Responses API
用 previous_response_id 继续对话。
只有声明 openai.responses 的模型才能使用 Responses。支持 Chat Completions 不代表支持 Responses。用 GET /openai/v1/models?api=responses 查询;2026-10-13 返回 deepseek-flash 和 glm-5.3-flash。
1. 准备终端
准备 Python 3.10+ 和 uv。将 Praxis 云 API Key 放入环境变量 PRAXIS_API_KEY,不要写入代码或日志。
test -n "$PRAXIS_API_KEY"期望:退出码为 0。退出码 1 表示变量未设置,先设置再继续。示例默认使用 https://api.deepraxis.ai。切换环境时,将 PRAXIS_API_BASE 设为相应 API 域名,不带末尾斜杠或 API 路径。
2. 接着上一条响应提问
平台会展开 previous_response_id 引用的历史。第二次调用只发送新问题和第一条响应 ID。两次使用相同 Key 和模型;示例检查第二条回答能取回未出现在新问题中的代码。
保存为 responses.py,运行 uv run -q --no-project --with openai --with anthropic --with google-genai python responses.py。
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ['PRAXIS_API_KEY'],
base_url=os.environ.get('PRAXIS_API_BASE', 'https://api.deepraxis.ai') + '/openai/v1')
models = client.models.list(extra_query={'api': 'responses'})
print('X-Request-Id:', models._request_id)
assert 'deepseek-flash' in [model.id for model in models]
first = client.responses.create(model='deepseek-flash',
input='Remember this code: LIME-742. Reply OK.',
reasoning={'effort': 'none'}, max_output_tokens=512)
print('X-Request-Id:', first._request_id)
assert first.status == 'completed' and first.id
second = client.responses.create(model='deepseek-flash',
previous_response_id=first.id, input='What was the code? Reply with only the code.',
reasoning={'effort': 'none'}, max_output_tokens=512)
print('X-Request-Id:', second._request_id)
assert second.status == 'completed' and 'LIME-742' in second.output_text
assert second.usage is not None
print('answer:', second.output_text)
print('usage:', second.usage.model_dump())期望:两条响应均为 completed,第二条回答包含 LIME-742 并打印用量,退出码 0。复用历史不意味着输入免费,应逐轮查看 usage。
限制与实测失败
POST /openai/v1/responses/compact 与 POST /openai/v1/responses/input_tokens 当前返回 HTTP 501,错误码 not_implemented。不要依赖它们压缩对话或预先计数;由应用控制历史长度,完成后读取实际用量。
用 gpt-5.6-sol 请求实测返回 HTTP 404,错误码 model_protocol_not_offered。改选 Responses 筛选目录中的模型。若示例目录断言失败,先重查该目录再重试。其他网关的响应 ID 不随地址迁移,应重建必要的历史。
参数见生成响应,各操作支持状态见 OpenAI API 参考。