> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 视觉示例

> 使用兼容 OpenAI 的多模态 Chat Completions 请求分析图片。

将 `IMAGE_URL` 设为模型供应商可以访问的 HTTPS 图片，然后在同一 User Message 中发送文本与图片。

<CodeGroup>
  ```bash Curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
  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}"
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  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);
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  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"])
  ```
</CodeGroup>

<Warning>转发用户 URL 前必须校验 SSRF、大小和媒体类型。私有图片应使用短期签名 URL。</Warning>
