中国站
帮助中心 > 人工智能 > 大模型服务 > API参考 > Image > Gemini 3.0 Pro Image Preview API 文档

Gemini 3.0 Pro Image Preview API 文档

Gemini 3.0 Pro Image Preview API 文档

概述

Gemini 3.0 Pro Image Preview 是一款支持:

  • 文生图(Text-to-Image)
  • 图生图(Image-to-Image)
  • 图片编辑(Image Editing)
  • 图片理解(Vision)
  • 多图融合(Multi-Image Composition)

的多模态模型。

接口兼容 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 固定为 google/gemini-3-pro-image-preview
messages array 对话消息
temperature number 采样温度
max_completion_tokens integer 最大输出Token
stream boolean 是否流式输出

文生图

请求示例

  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":"google/gemini-3-pro-image-preview",
  6. "messages":[
  7. {
  8. "role":"user",
  9. "content":"生成一只戴着宇航员头盔的橘猫"
  10. }
  11. ]
  12. }'

响应示例

  1. {
  2. "id": "chatcmpl_3ca318e6a156443595445b0fcd45acaa",
  3. "object": "chat.completion",
  4. "created": 1779778659,
  5. "model": "gemini-3-pro-image-preview",
  6. "choices": [
  7. {
  8. "index": 0,
  9. "message": {
  10. "role": "assistant",
  11. "content": "",
  12. "refusal": null,
  13. "annotations": null,
  14. "images": [
  15. {
  16. "type": "image_url",
  17. "index": 0,
  18. "image_url": {
  19. "url": "data:image/jpeg;base64,/9j/4AAQSk..."
  20. }
  21. }
  22. ],
  23. "reasoning_content": "",
  24. "function_call": null,
  25. "tool_calls": null,
  26. "reasoning_details": []
  27. },
  28. "finish_reason": "stop",
  29. "native_finish_reason": "STOP",
  30. "logprobs": null
  31. }
  32. ],
  33. "usage": {
  34. "prompt_tokens": 14,
  35. "completion_tokens": 1404,
  36. "total_tokens": 1418,
  37. "completion_tokens_details": {
  38. "accepted_prediction_tokens": 0,
  39. "audio_tokens": 0,
  40. "image_tokens": 1404,
  41. "reasoning_tokens": 0,
  42. "rejected_prediction_tokens": 0
  43. },
  44. "prompt_tokens_details": null,
  45. "cache_creation_input_tokens": null,
  46. "cache_creation": null,
  47. "gemini_cache_tokens_details": null
  48. },
  49. "system_fingerprint": null,
  50. "service_tier": null,
  51. "logprobs": null
  52. }

图片编辑

支持 Base64 图片输入。

请求示例

  1. {
  2. "model":"google/gemini-3-pro-image-preview",
  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. "model":"google/gemini-3-pro-image-preview",
  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_1"
  14. },
  15. {
  16. "type":"image",
  17. "image":"data:image/png;base64,IMAGE_2"
  18. }
  19. ]
  20. }
  21. ]
  22. }

图片理解

请求示例

  1. {
  2. "model":"google/gemini-3-pro-image-preview",
  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_vision001",
  3. "object":"chat.completion",
  4. "created":1779778659,
  5. "model":"google/gemini-3-pro-image-preview",
  6. "choices":[
  7. {
  8. "index":0,
  9. "message":{
  10. "role":"assistant",
  11. "content":"图片中是一位站在海边的人,背景是夕阳。",
  12. "refusal":null,
  13. "annotations":null,
  14. "images":[],
  15. "reasoning_content":"",
  16. "function_call":null,
  17. "tool_calls":null,
  18. "reasoning_details":[]
  19. },
  20. "finish_reason":"stop"
  21. }
  22. ]
  23. }

图片返回格式

生成图片不会返回公网 URL。

图片数据位于:

  1. choices[0].message.images[]

示例:

  1. {
  2. "images": [
  3. {
  4. "type": "image_url",
  5. "index": 0,
  6. "image_url": {
  7. "url": "data:image/jpeg;base64,/9j/4AAQSk..."
  8. }
  9. }
  10. ]
  11. }

Base64 图片解析

PHP示例

  1. $imageData = $response['choices'][0]['message']['images'][0]['image_url']['url'];
  2. $imageData = preg_replace(
  3. '#^data:image/\w+;base64,#i',
  4. '',
  5. $imageData
  6. );
  7. file_put_contents(
  8. 'output.jpg',
  9. base64_decode($imageData)
  10. );

Python示例

  1. import base64
  2. image_data = response["choices"][0]["message"]["images"][0]["image_url"]["url"]
  3. image_data = image_data.split(",", 1)[1]
  4. with open("output.jpg", "wb") as f:
  5. f.write(base64.b64decode(image_data))

流式输出

请求示例

  1. {
  2. "model":"gemini-3-pro-image-preview",
  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. "images":[
  15. {
  16. "type":"image_url",
  17. "image_url":{
  18. "url":"data:image/jpeg;base64,/9j/4AAQSk..."
  19. }
  20. }
  21. ]
  22. }
  23. }
  24. ]
  25. }
  26. data: [DONE]

Usage

返回示例

  1. {
  2. "usage": {
  3. "prompt_tokens": 14,
  4. "completion_tokens": 1404,
  5. "total_tokens": 1418,
  6. "completion_tokens_details": {
  7. "accepted_prediction_tokens": 0,
  8. "audio_tokens": 0,
  9. "image_tokens": 1404,
  10. "reasoning_tokens": 0,
  11. "rejected_prediction_tokens": 0
  12. }
  13. }
  14. }

字段说明

字段 说明
prompt_tokens 输入Token
completion_tokens 输出Token
total_tokens 总Token
image_tokens 图片生成Token
reasoning_tokens 推理Token
audio_tokens 音频Token

获取模型列表

Endpoint

  1. GET /v1/models

响应示例

  1. {
  2. "object":"list",
  3. "data":[
  4. {
  5. "id":"gemini-3-pro-image-preview",
  6. "object":"model",
  7. "created":1779778659,
  8. "owned_by":"google"
  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": "Invalid image format.",
  4. "type": "invalid_request_error",
  5. "code": "invalid_image"
  6. }
  7. }

请求频率超限

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

支持格式

输入图片

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

返回图片

  1. data:image/jpeg;base64,...