ai大模型调用协议
传输层
- http/https
- sse
- websocket
- grpc
目前主要的大模型api调用使用http+sse实现请求建立与大模型回答的增量推送。
api规范层
- openAI 协议
| 协议 | 端点 | 会话模型 | 特点 |
|---|---|---|---|
| Chat Completions | POST /chat/completions | 无状态messages[]数组 | 每次需要携带完整上下文,兼容性最广 |
| Response API | POST /responses | 有状态 | 新协议,支持长时agent,内置工具调用,推理过程独立输出 |
Chat Completions示例:
curl -L -X POST 'https://api.deepseek.com/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"messages": [
{
"content": "You are a helpful assistant",
"role": "system"
},
{
"content": "Hi",
"role": "user"
}
],
"model": "deepseek-flash",
"thinking": {
"type": "enabled"
},
"reasoning_effort": "none",
"max_tokens": 4096,
"response_format": {
"type": "text"
},
"stop": null,
"stream": false,
"stream_options": null,
"temperature": 1,
"top_p": 1,
"tools": null,
"tool_choice": "none",
"logprobs": false,
"top_logprobs": null
}'
Response API 示例:
curl -L -X POST 'https://api.deepseek.com/responses' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"model": "deepseek-flash",
"input": "string",
"instructions": "string",
"reasoning": {
"effort": "none"
},
"max_output_tokens": 4096,
"stream": false,
"temperature": 1,
"top_p": 1,
"text": {
"format": {
"type": "text",
"name": "string",
"schema": {}
}
},
"tools": null,
"tool_choice": "none",
"top_logprobs": null,
"user": "string"
}'
- Anthropic Messages 协议
- 端点:POST /v1/messages
- 结构:system顶层 + messages[](仅user/assistant交替),content为block数组
- 工具调用:通过tool_use block和tool_result block实现
- 思考能力:thinking: {budget_tokens},思考过程作为独立content block输出
- Google Gemini 原生协议
- 端点:/gemini/v1beta/models/{model}:generateContent(非流式)和:streamGenerateContent(流式)
- 认证:使用x-goog-api-key Header
- 特点:模型名称置于URL路径中,而非请求体内
- 其他协议
agent协作层
- mcp
- A2A
- AG-UI

浙公网安备 33010602011771号