/messages

AnthropicのAPIフォーマットを使用してメッセージの送受信を行います。このエンドポイントはClaudeおよび他のAnthropic形式のAPIと互換性があります。

POST
/v1/messages

構造化された入力メッセージのリストを送信し、モデルが生成したメッセージを受信します。

リクエストボディ

model使用するモデル(必須)
messagesメッセージオブジェクトの配列(必須)
max_tokens生成する最大トークン数(必須)
systemシステム指示またはコンテキスト(オプション)
streamサーバー送信イベントのストリーミングを有効化(オプション)
temperatureサンプリングのランダム性制御(オプション)
toolsツール使用で利用可能な関数(オプション)
tool_choiceツール呼び出しの動作(オプション)
reasoning思考(推論)の制御(オプション)。{"effort": "low"} で強度、{"max_tokens": 2000} で思考トークンの上限、{"enabled": false} でオフ。対応モデルと既定値は 思考(推論)の制御を参照
Request Body
{
  "model": "your-model",
  "max_tokens": 1024,
  "system": "You are a helpful assistant.",
  "messages": [
    {"role": "user", "content": "Hello!"}
  ],
  "reasoning": {"effort": "low"}
}

Anthropic 形式の thinking パラメータ({"type": "enabled", "budget_tokens": ...} / {"type": "disabled"})は、OpenRouter 経由のモデルでは効きません。2026-09-03 に kimi-k3 へ {"type": "disabled"} を送っても thinking ブロックが返りました。このエンドポイントでも reasoning オブジェクトを使ってください。

レスポンス

コンテンツ配列、モデル識別子、停止理由、トークン使用量メトリクスを含むメッセージオブジェクトを返します。

Response
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "your-model",
  "content": [
    {"type": "thinking", "thinking": "The user greeted me..."},
    {"type": "text", "text": "Hello! How can I help you today?"}
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 20,
    "output_tokens": 45
  }
}

推論モデルでは、思考が content 配列の {"type": "thinking"} ブロックとして text ブロックの前に返ります(ストリーミングでは thinking_delta)。そのトークンは usage.output_tokens に含まれ、出力単価で課金されます。