メインコンテンツへスキップ
YouRouter はテキスト以外にも、画像理解やプロバイダー固有の多モーダル形式、動画生成タスクに対応します。

どの API を使うべきか

用途推奨 APIメモ
テキストチャットPOST /v1/chat/completions標準的な OpenAI 互換呼び出し
画像理解POST /v1/chat/completionsimage_url ブロックを送る
Gemini ネイティブ多モーダルPOST /v1/projects/...:generateContentGoogle ネイティブの contents / parts が必要な場合
Claude ネイティブ MessagesPOST /v1/messagesAnthropic ネイティブの Messages が必要な場合
テキスト to ビデオ / 画像 to ビデオPOST /api/v3/contents/generations/tasksタスク作成 → ポーリング
多くのチャットとビジョン用途では、https://api.yourouter.ai/v1 と Chat Completions から始めるのが最短です。

Chat Completions で画像入力する

messages[].content をブロック配列にします。通常は text と 1 つ以上の image_url を並べます。
curl https://api.yourouter.ai/v1/chat/completions \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Describe this image in one sentence."
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://example.com/image.jpg"
            }
          }
        ]
      }
    ]
  }'
生成結果は通常ここです。
choices[0].message.content

Base64 画像入力

非公開画像は data URL を使います。
{
  "type": "image_url",
  "image_url": {
    "url": "data:image/png;base64,<BASE64_IMAGE>"
  }
}
ペイロードが大きくなりすぎないよう注意してください。大きい画像は一時的な HTTPS URL を推奨します。

Python 例

import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["YOUROUTER_API_KEY"],
    base_url="https://api.yourouter.ai/v1",
)

with open("image.jpg", "rb") as image_file:
    encoded = base64.b64encode(image_file.read()).decode("utf-8")

completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What is shown in this image?"},
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/jpeg;base64,{encoded}"},
                },
            ],
        }
    ],
)

print(completion.choices[0].message.content)

Gemini ネイティブ多モーダル

Google の generateContent 形式が必要な場合に使います。
curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "vendor: google" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          { "text": "Describe this image in one sentence." },
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'
参照: Google Generate Content

Claude ネイティブ Messages

Claude ネイティブの挙動が必要な場合に使います。
curl https://api.yourouter.ai/v1/messages \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -H "vendor: anthropic" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 300,
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Describe this image in one sentence." },
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/jpeg",
              "data": "<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'
参照: Anthropic Messages

動画生成タスク

動画生成はタスク型です。作成してからポーリングします。
curl -X POST https://api.yourouter.ai/api/v3/contents/generations/tasks \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedance-1-0-pro-250528",
    "content": [
      {
        "type": "text",
        "text": "A cinematic product shot with soft studio lighting --duration 5 --resolution 1080p"
      }
    ]
  }'
作成レスポンスの id を使って状態を確認します。
curl https://api.yourouter.ai/api/v3/contents/generations/tasks/{id} \
  -H "Authorization: Bearer $YOUROUTER_API_KEY"
詳細は Ark テキスト to ビデオ を参照してください。

実装のコツ

  • モデル ID は設定化しておくと、ビジョン系の切替が容易です。
  • vendor はプロバイダー固有フォーマットや挙動が必要なときだけ使います。
  • 大きい画像は HTTPS URL、ローカル検証は base64 data URL が扱いやすいです。
  • 上流固有の不具合調査ではレスポンスのリクエスト ID を残します。