回收站與歸檔
本頁保留源文檔中的回收站內容,便於後續查閱與遷移。
回收站
POST 圖片生成(Nano-banana2-4K)
POST /chat/completions
Gemini 也提供了圖像生成能力,作為一種替代方案。與 Imagen 3.0 相比,Gemini 的圖像生成更適合於需要上下文理解和推理的場景,而非追求極致的藝術表現和視覺質量。
更高的視覺質量 → 相比 exp 版,圖像更銳利、更豐富、更清晰。 更準確的文本呈現 → 生成的視覺中,文本更加精準、乾淨、易讀。 顯著減少過濾攔截 → 得益於更智能、寬鬆的過濾機制,創作時幾乎不再被打斷。 說明:
模型 id:gemini-2.0-flash-preview-image-generation 費率(輸入→輸出): 0.1 → 0.1→0.4/M tokens 需要新增參數來體驗新特性 "modalities":["text","image"] 圖片以 Base64 編碼形式傳遞與輸出 作為實驗模型,建議明確指出 “輸出圖片”,否則可能只有文本 輸出圖片的默認高度為 1024px python 調用需要最新的 openai sdk 支持,請先運行 pip install -U openai 瞭解更多請訪問 Gemini 官方文檔
Body 請求參數
{
"model": "gemini-3-pro-image-preview-4k",
"messages": [
{
"role": "user",
"content": "Generate an infographic of the current weather in Tokyo."
}
]
}
請求參數
| 名稱 | 位置 | 類型 | 必選 | 說明 |
|---|---|---|---|---|
| Content-Type | header | string | 是 | none |
| Accept | header | string | 是 | none |
| Authorization | header | string | 否 | none |
| body | body | object | 否 | none |
| » model | body | string | 是 | 要使用的模型的 ID。有關哪些模型適用於聊天 API 的詳細信息,請參閱模型端點兼容性表。 |
| » messages | body | [object] | 是 | 以聊天格式生成聊天完成的消息。 |
| »» role | body | string | 否 | none |
| »» content | body | string | 否 | none |
| » temperature | body | integer | 否 | 使用什麼採樣溫度,介於 0 和 2 之間。較高的值(如 0.8)將使輸出更加隨機,而較低的值(如 0.2)將使輸出更加集中和確定。 我們通常建議改變這個或top_p但不是兩者。 |
| » top_p | body | integer | 否 | 一種替代溫度採樣的方法,稱為核採樣,其中模型考慮具有 top_p 概率質量的標記的結果。所以 0.1 意味著只考慮構成前 10% 概率質量的標記。 我們通常建議改變這個或temperature但不是兩者。 |
| » n | body | integer | 否 | 為每個輸入消息生成多少個聊天完成選項。 |
| » stream | body | boolean | 否 | 如果設置,將發送部分消息增量,就像在 ChatGPT 中一樣。當令牌可用時,令牌將作為純數據服務器發送事件data: [DONE]發送,流由消息終止。有關示例代碼,請參閱 OpenAI Cookbook 。 |
| » stop | body | string | 否 | API 將停止生成更多令牌的最多 4 個序列。 |
| » max_tokens | body | integer | 否 | 聊天完成時生成的最大令牌數。 輸入標記和生成標記的總長度受模型上下文長度的限制。 |
| » presence_penalty | body | number | 否 | -2.0 和 2.0 之間的數字。正值會根據到目前為止是否出現在文本中來懲罰新標記,從而增加模型談論新主題的可能性。 查看有關頻率和存在懲罰的更多信息。 |
| » frequency_penalty | body | number | 否 | -2.0 和 2.0 之間的數字。正值會根據新標記在文本中的現有頻率對其進行懲罰,從而降低模型逐字重複同一行的可能性。 查看有關頻率和存在懲罰的更多信息。 |
| » logit_bias | body | null | 否 | 修改指定標記出現在完成中的可能性。 接受一個 json 對象,該對象將標記(由標記器中的標記 ID 指定)映射到從 -100 到 100 的關聯偏差值。從數學上講,偏差會在採樣之前添加到模型生成的 logits 中。確切的效果因模型而異,但 -1 和 1 之間的值應該會減少或增加選擇的可能性;像 -100 或 100 這樣的值應該導致相關令牌的禁止或獨佔選擇。 |
| » user | body | string | 否 | 代表您的最終用戶的唯一標識符,可以幫助 OpenAI 監控和檢測濫用行為。瞭解更多。 |
返回示例
200 Response
{
"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
}
}
返回結果
| 狀態碼 | 狀態碼含義 | 說明 | 數據模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
返回數據結構
狀態碼 200
| 名稱 | 類型 | 必選 | 約束 | 中文名 | 說明 |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |