響應 API
響應 API 提供了一個有状態的高層接口,用於與 Link Astra 模型交互。它會管理對話状態、支援工具調用,並能在單次請求中执行多步骤的智能體工作流。
POST https://api.linkastra.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://api.linkastra.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://api.linkastra.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) — 详細的工具使用指南