メインコンテンツへスキップ

Documentation Index

Fetch the complete documentation index at: https://docs.apigo.ai/llms.txt

Use this file to discover all available pages before exploring further.

推奨エンドポイント

最低限のお願い

{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "Extract order fields and return JSON only." }]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "{" }]
    }
  ]
}

cURLの例

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [{ "type": "text", "text": "Extract order fields and return JSON only." }]
      },
      {
        "role": "assistant",
        "content": [{ "type": "text", "text": "{" }]
      }
    ]
  }'

Python の例

from anthropic import Anthropic

client = Anthropic(api_key="<ANTHROPIC_API_KEY>")

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [{"type": "text", "text": "Extract order fields and return JSON only."}],
        },
        {
            "role": "assistant",
            "content": [{"type": "text", "text": "{"}],
        },
    ],
)

print(response.content[0].text)

Node.js の例

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [{ type: "text", text: "Extract order fields and return JSON only." }]
    },
    {
      role: "assistant",
      content: [{ type: "text", text: "{" }]
    }
  ]
});

console.log(response.content[0].text);

ベストプラクティス

  • Anthropic の JSON モード ガイダンスに従ってください: ターゲット構造を正確に指定します
  • より厳格な出力一貫性が必要な場合は、アシスタントの応答を事前入力します
  • 大規模なスキーマの場合は、1 行の指示に頼るのではなく、例を追加します。