中国站
帮助中心 > 人工智能 > 大模型服务 > API参考 > TEXT > GPT-5.4 API 文档

GPT-5.4 API 文档

GPT-5.4 API 文档

概述

GPT-5.4 是一款支持文本生成、代码编写、推理分析、图片理解(Vision)、Function Calling 和 Structured Output 的大型语言模型。

兼容 OpenAI Chat Completions API。


Base URL

  1. https://api.yisu.com

认证方式

所有请求均需携带 API Key:

  1. Authorization: Bearer YOUR_API_KEY
  2. Content-Type: application/json

Chat Completions

Endpoint

  1. POST /v1/chat/completions

请求参数

参数 类型 必填 说明
model string 固定为 gpt-5.4
messages array 对话消息
temperature number 随机性控制
top_p number Top-P采样
max_completion_tokens integer 最大输出Token
stream boolean 是否流式输出
response_format object JSON输出模式
tools array Function Calling
tool_choice string/object 工具调用策略

基础对话

请求示例

  1. curl https://api.yisu.com/v1/chat/completions \
  2. -H "Authorization: Bearer YOUR_API_KEY" \
  3. -H "Content-Type: application/json" \
  4. -d '{
  5. "model":"gpt-5.4",
  6. "messages":[
  7. {
  8. "role":"user",
  9. "content":"你好"
  10. }
  11. ]
  12. }'

响应示例

  1. {
  2. "id": "chatcmpl_abc123",
  3. "object": "chat.completion",
  4. "created": 1780470861,
  5. "model": "gpt-5.4",
  6. "choices": [
  7. {
  8. "index": 0,
  9. "message": {
  10. "role": "assistant",
  11. "content": "你好!有什么可以帮助你的吗?"
  12. },
  13. "finish_reason": "stop"
  14. }
  15. ],
  16. "usage": {
  17. "prompt_tokens": 8,
  18. "completion_tokens": 12,
  19. "total_tokens": 20
  20. }
  21. }

多轮对话

请求示例

  1. {
  2. "model":"gpt-5.4",
  3. "messages":[
  4. {
  5. "role":"system",
  6. "content":"你是一名资深运维工程师"
  7. },
  8. {
  9. "role":"user",
  10. "content":"CentOS如何安装Nginx?"
  11. }
  12. ]
  13. }

图片理解(Vision)

支持 Base64 图片输入。

请求示例

  1. {
  2. "model":"gpt-5.4",
  3. "messages":[
  4. {
  5. "role":"user",
  6. "content":[
  7. {
  8. "type":"text",
  9. "text":"描述图片内容"
  10. },
  11. {
  12. "type":"image",
  13. "image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
  14. }
  15. ]
  16. }
  17. ]
  18. }

响应示例

  1. {
  2. "id":"chatcmpl_vision001",
  3. "object":"chat.completion",
  4. "created":1780470861,
  5. "model":"gpt-5.4",
  6. "choices":[
  7. {
  8. "message":{
  9. "role":"assistant",
  10. "content":"图片中是一只橘猫坐在沙发上。"
  11. },
  12. "finish_reason":"stop"
  13. }
  14. ]
  15. }

JSON 输出模式

请求示例

  1. {
  2. "model":"gpt-5.4",
  3. "messages":[
  4. {
  5. "role":"user",
  6. "content":"返回一个用户对象"
  7. }
  8. ],
  9. "response_format":{
  10. "type":"json_object"
  11. }
  12. }

响应示例

  1. {
  2. "name":"Tom",
  3. "age":25,
  4. "email":"tom@example.com"
  5. }

Function Calling

请求示例

  1. {
  2. "model":"gpt-5.4",
  3. "messages":[
  4. {
  5. "role":"user",
  6. "content":"上海天气怎么样?"
  7. }
  8. ],
  9. "tools":[
  10. {
  11. "type":"function",
  12. "function":{
  13. "name":"get_weather",
  14. "description":"获取天气信息",
  15. "parameters":{
  16. "type":"object",
  17. "properties":{
  18. "city":{
  19. "type":"string"
  20. }
  21. },
  22. "required":["city"]
  23. }
  24. }
  25. }
  26. ]
  27. }

响应示例

  1. {
  2. "choices":[
  3. {
  4. "message":{
  5. "role":"assistant",
  6. "tool_calls":[
  7. {
  8. "id":"call_001",
  9. "type":"function",
  10. "function":{
  11. "name":"get_weather",
  12. "arguments":"{\"city\":\"上海\"}"
  13. }
  14. }
  15. ]
  16. },
  17. "finish_reason":"tool_calls"
  18. }
  19. ]
  20. }

流式输出

请求示例

  1. {
  2. "model":"gpt-5.4",
  3. "stream":true,
  4. "messages":[
  5. {
  6. "role":"user",
  7. "content":"介绍一下Linux"
  8. }
  9. ]
  10. }

SSE响应

  1. data: {
  2. "choices":[
  3. {
  4. "delta":{
  5. "content":"Linux"
  6. }
  7. }
  8. ]
  9. }
  10. data: {
  11. "choices":[
  12. {
  13. "delta":{
  14. "content":" 是一个开源操作系统..."
  15. }
  16. }
  17. ]
  18. }
  19. data: [DONE]

Usage

标准格式

  1. {
  2. "usage": {
  3. "prompt_tokens": 120,
  4. "completion_tokens": 280,
  5. "total_tokens": 400
  6. }
  7. }

获取模型列表

Endpoint

  1. GET /v1/models

响应示例

  1. {
  2. "object":"list",
  3. "data":[
  4. {
  5. "id":"gpt-5.4",
  6. "object":"model",
  7. "created":1780000000,
  8. "owned_by":"system"
  9. }
  10. ]
  11. }

错误响应

API Key无效

  1. {
  2. "error":{
  3. "message":"Invalid API key.",
  4. "type":"authentication_error",
  5. "code":"invalid_api_key"
  6. }
  7. }

请求频率超限

  1. {
  2. "error":{
  3. "message":"Rate limit exceeded.",
  4. "type":"rate_limit_error",
  5. "code":"rate_limit_exceeded"
  6. }
  7. }

参数错误

  1. {
  2. "error":{
  3. "message":"Invalid request.",
  4. "type":"invalid_request_error",
  5. "code":"invalid_request"
  6. }
  7. }