响应 API
响应 API 提供了一个有状态的高层接口,用于与 LW AI 模型交互。它会管理对话状态、支持工具调用,并能在单次请求中执行多步骤的智能体工作流。
POST https://openapi.linkwo.ai/v1/responses注意: 响应 API 仅对部分模型开放。兼容性请查阅模型概览。
请求体
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID |
input | string/array | 是 | 用户输入或对话历史 |
instructions | string | 否 | 系统级指令 |
tools | array | 否 | 可用工具(网页搜索、文件搜索、代码解释器、函数) |
tool_choice | string/object | 否 | 工具选择模式 |
temperature | float | 否 | 采样温度(0–2) |
max_output_tokens | integer | 否 | 最大输出 token 数 |
previous_response_id | string | 否 | 从上一次响应继续 |
stream | boolean | 否 | 通过 SSE 流式返回结果 |
请求示例
curl https://openapi.linkwo.ai/v1/responses \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4-pro",
"input": "What are the key differences between REST and GraphQL?"
}'响应
{
"id": "resp_abc123",
"object": "response",
"created_at": 1719000000,
"model": "deepseek/deepseek-v4-pro",
"status": "completed",
"output": [
{
"type": "message",
"id": "msg_abc123",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "REST and GraphQL are two approaches to building APIs..."
}
]
}
],
"usage": {
"input_tokens": 15,
"output_tokens": 200,
"total_tokens": 215
}
}
```bash
## 使用 previous_response_id 进行多轮对话
传入 `previous_response_id` 即可延续对话,无需重新发送完整历史:
```python
from openai import OpenAI
client = OpenAI(
base_url="https://openapi.linkwo.ai/v1",
api_key="YOUR_API_KEY"
)
response_1 = client.responses.create(
model="deepseek/deepseek-v4-pro",
input="What is machine learning?"
)
response_2 = client.responses.create(
model="deepseek/deepseek-v4-pro",
input="How is it different from deep learning?",
previous_response_id=response_1.id
)使用工具
响应 API 支持内置工具和自定义函数调用:
response = client.responses.create(
model="deepseek/deepseek-v4-pro",
input="What's the weather in Beijing?",
tools=[{
"type": "function",
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}]
)
```bash
## 相关文档
- [对话补全](../api-reference/chat-completions) — 更底层的对话 API
- [函数调用](../api-reference/function-calling) — 详细的工具使用指南