OpenAI GPT API
鉴权方式
- Header:
Authorization: Bearer $OPENAI_API_KEY - Header:
Content-Type: application/json
Chat completions
- 方法:
POST - 地址:
https://api.openai.com/v1/chat/completions - 用途:兼容式 Chat Completions 接口
Chat completions 请求参数
Chat completions 请求示例
curl
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "VAR_chat_model_id",
"messages": [
{
"role": "developer",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'Chat completions 请求返回结果
Chat completions 请求返回示例
{
"id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
"object": "chat.completion",
"created": 1741569952,
"model": "gpt-5.4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?",
"refusal": null,
"annotations": []
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 10,
"total_tokens": 29,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
}
,
"service_tier": "default"
}Responses
- 方法:
POST - 地址:
https://api.openai.com/v1/responses - 用途:统一文本生成、多模态输入、结构化输出、工具调用、流式输出
Responses 请求参数
Responses 请求示例
curl
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-5",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Write a concise product launch announcement for GGPU Platform."
}
]
}
],
"instructions": "Use a professional but energetic tone.",
"max_output_tokens": 300,
"temperature": 0.7,
"text": {
"format": {
"type": "text"
}
}
}'Responses 请求返回结果
Responses 请求返回示例
{
"id": "resp_67cb71b351908190a308f3859487620d06981a8637e6bc44",
"object": "response",
"created_at": 1741386163,
"status": "completed",
"error": null,
"incomplete_details": null,
"instructions": "Use a professional but energetic tone.",
"max_output_tokens": 300,
"model": "gpt-5",
"output": [
{
"id": "msg_67cb71b4223c8190a8f3859487620d06",
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "GGPU Platform is now available, bringing teams a faster and more reliable way to build, run, and scale intelligent workflows.",
"annotations": []
}
]
}
],
"output_text": "GGPU Platform is now available, bringing teams a faster and more reliable way to build, run, and scale intelligent workflows.",
"parallel_tool_calls": true,
"previous_response_id": null,
"reasoning": {
"effort": null,
"summary": null
},
"service_tier": "default",
"store": true,
"temperature": 0.7,
"text": {
"format": {
"type": "text"
}
},
"tool_choice": "auto",
"tools": [],
"top_p": null,
"truncation": "disabled",
"usage": {
"input_tokens": 31,
"output_tokens": 28,
"total_tokens": 59,
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"user": null,
"metadata": {}
}