Anthropic Messages
ファイルを入力する場合は ファイル API でアップロードし、返された file_id を参照します。ゲートウェイは変換を担当し、入力への対応可否は上流が判断します。
messages[].content に {"type":"document","source":{"type":"file","file_id":"..."}} を指定します。画像は type: image、音声・動画は拡張型 audio・video を使い、実ファイルの種類に一致させます。/v1/messages/count_tokens も対応します。
POST /v1/messages は Anthropic 互換の Messages API です。choices ではなく、Claude 形式の content blocks、max_tokens、system、stop_reason を期待するクライアントに適しています。
エンドポイント
https://api.inoneapi.com/v1/messages
# -H "X-APP-NAME: Your App Name"
# -H "X-APP-URL: https://your-app.example.com"
curl "https://api.inoneapi.com/v1/messages" \
-H "x-api-key: $INONEAPI_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_MODEL_ID",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'パラメーター
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
| model | string | はい | Anthropic プロトコル対応が有効な InOneAPI 公開モデル ID。 |
| max_tokens | number | はい | 最大生成 token 数。Anthropic 形式では必須です。 |
| messages | array | はい | 順序付き会話ターン。role は通常 user と assistant。 |
| system | string/array | いいえ | messages 配列の外に置くシステム指示。 |
| temperature | number | いいえ | サンプリングのランダム性。モデルとプロバイダー制限に従います。 |
| top_p | number | いいえ | nucleus sampling の制御。 |
| top_k | number | いいえ | 対応時に使う Anthropic 形式の候補数制限。 |
| stop_sequences | array | いいえ | カスタム停止文字列。 |
| stream | boolean | いいえ | 対応時に Anthropic イベントストリームを返します。 |
| tools | array | いいえ | Anthropic 互換のツール定義。 |
| tool_choice | object | いいえ | ツール利用を自動、必須、指定名に制御します。 |
| metadata | object | いいえ | アプリ側メタデータ。秘密情報は入れません。 |
Content blocks
メッセージ content は文字列、または型付き block 配列です。最も一般的なのは text block です。Vision 対応モデルでは、マッピングに応じて image block を受け付けます。
{
"role": "user",
"content": [
{ "type": "text", "text": "主要なリスクを抽出してください。" }
]
}
Anthropic の tool use を使う場合、ツール結果は user message の tool_result block として返します。モデルが返した tool ID はそのまま保持してください。
レスポンス
レスポンスには assistant content blocks と Anthropic 形式の token usage が含まれます。
{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "YOUR_MODEL_ID",
"content": [
{ "type": "text", "text": "入口で安定した Trace ID を発行するところから始めます..." }
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 42,
"output_tokens": 28
}
}
Token カウント
対応マッピングで公開されている場合、POST /v1/messages/count_tokens で入力 token を見積もれます。リクエスト本文は Messages と同じ形式で、input_tokens を返します。
curl https://api.inoneapi.com/v1/messages/count_tokens \
-H "Authorization: Bearer $INONEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL_ID",
"messages": [
{ "role": "user", "content": "これを数えてください。" }
]
}'
ストリーミングとエラー
ストリーミングはプロバイダー形式のイベントを返します。content delta、tool-use delta、message stop、終端エラーを分けて処理してください。診断には X-Gateway-Trace-ID を保存します。
よくある失敗は max_tokens の不足、未対応の content block、モデル制限、予算制限、上流マッピングエラーです。401/403 はキーと権限、429 は予算またはレート、5xx は Trace ID とともにゲートウェイまたは上流を確認します。