中国站
帮助中心 > 人工智能 > 大模型服务 > API参考 > Image > GPT-5.4-Image-2 兼容 OpenAI Chat Completions API文档

GPT-5.4-Image-2 兼容 OpenAI Chat Completions API文档

GPT-5.4-Image-2 API 文档

概述

GPT-5.4-Image-2 是一款支持文生图、图生图、图片编辑和图片理解的多模态模型。

接口兼容 OpenAI Chat Completions API。

Base URL

  1. https://api.yisu.com

认证

所有请求均需携带 API Key。

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

创建图片

Endpoint

  1. POST /v1/chat/completions

请求参数

Request Body

参数 类型 必填 说明
model string 固定为 gpt-5.4-image-2
messages array 对话消息
stream boolean 是否流式输出
size string 图片尺寸
quality string 图片质量
n integer 生成图片数量

支持尺寸

  1. 1024x1024
  2. 1024x1536
  3. 1536x1024
  4. auto

支持质量

  1. low
  2. medium
  3. high
  4. auto

文生图

请求示例

  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-image-2",
  6. "messages":[
  7. {
  8. "role":"user",
  9. "content":"生成一只坐在月球上的橘猫,超写实风格"
  10. }
  11. ]
  12. }'

响应示例

  1. {
  2. "id": "chatcmpl_img_A1B2C3",
  3. "object": "chat.completion",
  4. "created": 1780470861,
  5. "model": "gpt-5.4-image-2",
  6. "choices": [
  7. {
  8. "index": 0,
  9. "message": {
  10. "role": "assistant",
  11. "content": [
  12. {
  13. "type": "image_base64",
  14. "image_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
  15. }
  16. ]
  17. },
  18. "finish_reason": "stop"
  19. }
  20. ],
  21. "usage": {
  22. "prompt_tokens": 42,
  23. "completion_tokens": 1560,
  24. "total_tokens": 1602
  25. }
  26. }

图片编辑(Base64)

支持上传 Base64 图片进行编辑。


请求示例

  1. {
  2. "model": "gpt-5.4-image-2",
  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_img_edit_001",
  3. "object": "chat.completion",
  4. "created": 1780470861,
  5. "model": "gpt-5.4-image-2",
  6. "choices": [
  7. {
  8. "index": 0,
  9. "message": {
  10. "role": "assistant",
  11. "content": [
  12. {
  13. "type": "image_base64",
  14. "image_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
  15. }
  16. ]
  17. },
  18. "finish_reason": "stop"
  19. }
  20. ]
  21. }

多图编辑

支持同时上传多张图片。

请求示例

  1. {
  2. "model": "gpt-5.4-image-2",
  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,IMAGE_BASE64_1"
  14. },
  15. {
  16. "type": "image",
  17. "image": "data:image/png;base64,IMAGE_BASE64_2"
  18. }
  19. ]
  20. }
  21. ]
  22. }

图片理解

分析图片内容。

请求示例

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

响应示例

  1. {
  2. "id": "chatcmpl_vision_001",
  3. "object": "chat.completion",
  4. "created": 1780470861,
  5. "model": "gpt-5.4-image-2",
  6. "choices": [
  7. {
  8. "message": {
  9. "role": "assistant",
  10. "content": "图片中是一只橘猫坐在窗台上,阳光从左侧照射进来。"
  11. },
  12. "finish_reason": "stop"
  13. }
  14. ]
  15. }

流式输出

请求示例

  1. {
  2. "model":"gpt-5.4-image-2",
  3. "stream":true,
  4. "messages":[
  5. {
  6. "role":"user",
  7. "content":"生成一辆未来概念跑车"
  8. }
  9. ]
  10. }

SSE响应示例

  1. data: {
  2. "choices":[
  3. {
  4. "delta":{
  5. "content":"正在生成图片..."
  6. }
  7. }
  8. ]
  9. }
  10. data: {
  11. "choices":[
  12. {
  13. "delta":{
  14. "image_base64":"iVBORw0KGgoAAAANSUhEUgAA..."
  15. }
  16. }
  17. ]
  18. }
  19. data: [DONE]

Usage 字段

标准格式

  1. {
  2. "usage": {
  3. "prompt_tokens": 135,
  4. "completion_tokens": 1800,
  5. "total_tokens": 1935
  6. }
  7. }

扩展格式

  1. {
  2. "usage": {
  3. "prompt_tokens": 135,
  4. "completion_tokens": 1800,
  5. "total_tokens": 1935,
  6. "prompt_tokens_details": {
  7. "cached_tokens": 0,
  8. "audio_tokens": 0
  9. },
  10. "completion_tokens_details": {
  11. "reasoning_tokens": 0,
  12. "audio_tokens": 0,
  13. "accepted_prediction_tokens": 0,
  14. "rejected_prediction_tokens": 0
  15. }
  16. }
  17. }

错误响应

认证失败

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

请求参数错误

  1. {
  2. "error": {
  3. "message": "Invalid image format.",
  4. "type": "invalid_request_error",
  5. "code": "invalid_image"
  6. }
  7. }

支持格式

输入图片

  1. PNG
  2. JPEG
  3. WEBP
  4. GIF

Base64格式

  1. data:image/png;base64,...
  2. data:image/jpeg;base64,...
  3. data:image/webp;base64,...