IMAGE_URL 设为模型供应商可以访问的 HTTPS 图片,然后在同一 User Message 中发送文本与图片。
curl https://api.yelu.ai/v1/chat/completions \
-H "Authorization: Bearer $YELU_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"生成简洁的 Alt Text。\"},{\"type\":\"image_url\",\"image_url\":{\"url\":\"$IMAGE_URL\",\"detail\":\"auto\"}}]}],\"max_completion_tokens\":120}"
const response = await fetch('https://api.yelu.ai/v1/chat/completions', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.YELU_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: [
{ type: 'text', text: '生成简洁的 Alt Text。' },
{ type: 'image_url', image_url: { url: process.env.IMAGE_URL, detail: 'auto' } },
] }],
max_completion_tokens: 120,
}),
});
if (!response.ok) throw new Error(await response.text());
console.log((await response.json()).choices[0].message.content);
import os
import requests
response = requests.post(
"https://api.yelu.ai/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['YELU_API_KEY']}"},
json={
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "生成简洁的 Alt Text。"},
{"type": "image_url", "image_url": {"url": os.environ["IMAGE_URL"], "detail": "auto"}},
]}],
"max_completion_tokens": 120,
},
timeout=120,
)
response.raise_for_status()
print(response.json()["choices"][0]["message"]["content"])
转发用户 URL 前必须校验 SSRF、大小和媒体类型。私有图片应使用短期签名 URL。