FastAPI
  1. 聊天(Chat)
FastAPI
  • 指南
  • 获取 Base URL 和 API Key
  • 通过 AI 快速生成调用代码
  • 列出模型
    • Models(列出模型)
      GET
  • 聊天(Chat)
    • 所有对话模型均兼容 OpenAI 格式
    • 聊天完成对象
    • 聊天完成块对象
    • Chat(聊天)
      POST
    • Chat(流式返回)
      POST
    • Chat(分析图片)
      POST
    • Chat(分析视频)
      POST
    • Chat(结构化输出)
      POST
    • Chat(兼容Recraftv3)
      POST
    • Chat(指定GPTs)
      POST
    • Chat(生成图片)
      POST
    • Chat(修改图片)
      POST
    • Chat(工具tools调用)
      POST
    • Chat(Claude Thinking)
      POST
    • gpt-3.5-turbo-instruct
      POST
  • 聊天(Responses)
    • Responses API与Chat API对比
    • 创建模型响应
      POST
    • 创建模型响应(流式返回)
      POST
    • 创建模型响应(调用联网
      POST
  • 视频模型
    • 视频生成模型简介
    • Sora2官方格式
      • 创建视频
      • 查询视频进度
  • 绘图模型
    • 生图模型简介
    • OpenAI 聊天格式
      • Chat(生成图片)
      • Chat(修改图片)
    • Nano-banana 官方格式
  1. 聊天(Chat)

Chat(结构化输出)

POST
/v1/chat/completions
官方指南
官方API文档
所有对话模型,都可使用此接口, 修改 model 属性为模型名
给定一个提示,该模型将返回一个或多个预测的完成,并且还可以返回每个位置的替代标记的概率。
为提供的提示和参数创建完成

请求参数

Header 参数

Body 参数application/json

示例
{
    "model": "gpt-4o-2024-08-06",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful math tutor. Guide the user through the solution step by step."
        },
        {
            "role": "user",
            "content": "9.11和9.8谁大"
        }
    ],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "name": "math_reasoning",
            "schema": {
                "type": "object",
                "properties": {
                    "steps": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "explanation": {
                                    "type": "string"
                                },
                                "output": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "explanation",
                                "output"
                            ],
                            "additionalProperties": false
                        }
                    },
                    "final_answer": {
                        "type": "string"
                    }
                },
                "required": [
                    "steps",
                    "final_answer"
                ],
                "additionalProperties": false
            },
            "strict": true
        }
    }
}

请求示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST '/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-4o-2024-08-06",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful math tutor. Guide the user through the solution step by step."
        },
        {
            "role": "user",
            "content": "9.11和9.8谁大"
        }
    ],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "name": "math_reasoning",
            "schema": {
                "type": "object",
                "properties": {
                    "steps": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "explanation": {
                                    "type": "string"
                                },
                                "output": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "explanation",
                                "output"
                            ],
                            "additionalProperties": false
                        }
                    },
                    "final_answer": {
                        "type": "string"
                    }
                },
                "required": [
                    "steps",
                    "final_answer"
                ],
                "additionalProperties": false
            },
            "strict": true
        }
    }
}'

返回响应

🟢200OK
application/json
Body

示例
{
    "id": "string",
    "object": "string",
    "created": 0,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "string",
                "content": "string"
            },
            "finish_reason": "string"
        }
    ],
    "usage": {
        "prompt_tokens": 0,
        "completion_tokens": 0,
        "total_tokens": 0
    }
}
修改于 2026-01-09 08:41:37
上一页
Chat(分析视频)
下一页
Chat(兼容Recraftv3)
Built with