Skip to main content
POST
Create chat completion
本頁使用與 建立對話補全 相同的 chat/completions 操作,上方 playground 已預先填入通用對話結構。以下說明如何從相容 OpenAI 的用戶端,透過這個端點請求由 Gemini 驅動的圖像生成。
請在 model 中指定圖像生成模型(例如 gemini-2.0-flash-preview-image-generation),依需求設定 stream,並透過 messages 提供 prompt。你也可以選擇加入 contents,搭配 messages 提供額外的 Gemini 風格多模態上下文。

供應商特定說明

contents 欄位是 DGrid 疊加在標準 chat completions 結構上的延伸。當目標模型支援時,它可讓你在 OpenAI 風格的 messages 陣列之外,再傳送 Gemini 原生的 parts(例如 inlineData)。

範例:請求圖像

回應欄位

回應遵循標準 chat completions 結構。生成圖像會直接嵌入在 assistant 訊息內容中:
array
回傳的 choice 條目。
object
Token 使用摘要。

回應範例

200

授權

Authorization
string
header
必填

Your DGrid API key. All endpoints use Authorization: Bearer <DGRID_API_KEY>.

主體

application/json
model
string
必填

Target model ID in provider/model-name format.

範例:

"openai/gpt-4o"

messages
object[]
必填

Conversation message list.

temperature
number
預設值:1

Sampling temperature.

top_p
number
預設值:1

Nucleus sampling value.

n
integer
預設值:1

Number of choices to generate.

stream
boolean
預設值:false

Enable SSE streaming.

max_tokens
integer

Maximum token count.

max_completion_tokens
integer

Max completion-only tokens.

presence_penalty
number
預設值:0

Presence penalty.

frequency_penalty
number
預設值:0

Frequency penalty.

logit_bias
object

Token bias configuration.

stop

Stop sequence string or array.

tools
object[]

Tool definitions.

tool_choice

Tool selection behavior. Defaults to auto.

response_format
object

Response schema or JSON mode config.

seed
integer

Deterministic seed.

user
string

End-user identifier.

回應

Chat completion result.

id
string

Completion identifier.

object
string

Always chat.completion.

created
integer

Creation timestamp.

model
string

Model that served the request.

choices
object[]

Returned choices.

usage
object

Token usage breakdown.

system_fingerprint
string