文生图
目前仅 gemini-2.0-flash-exp-image-generation
、gpt-4o-image
两个模型支持在对话中绘制图像,以下是通过对话画图的请求示例,和普通文本对话并无不同:
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o-image",
"messages": [
{
"role": "user",
"content": "画一辆吉卜力风格的保时捷911"
}
]
}'
gpt-4o-image
支持流式输出,gemini-2.0-flash-exp-image-generation
不支持流式输出。图片生成完成后,返回的 content
字段中会包含生成的图片 URL 地址,你可以通过正则进行提取,或者直接在支持 Markdown 渲染的组件中显示。
图生图
如果你想要以图生图,或者在已有的图片上进行修改,可以结合图片对话请求实现:
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o-image",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "将图片中的中文替换成英文GeekAI,字体风格大小保持不变"
},
{
"type": "image_url",
"image_url": {
"url": "https://static.geekai.co/icon/geekai-logo-main-tr.png"
}
}
]
}
]
}'
在上面的请求中,image_url
字段的 url
属性可以是任何有效的图片 URL 地址或者 Base64 编码的图片数据。