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

# Claude 基础对话示例

> Claude Messages API 的基础对话示例。

## 推荐 endpoint

* [Claude /v1/messages](/api-reference/endpoints/claude/text)

## 最小请求

```json theme={null}
{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "system": "You are a concise assistant.",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "用三句话介绍 ApiGo。" }]
    }
  ]
}
```

## cURL 示例

```bash theme={null}
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,
    "system": "You are a concise assistant.",
    "messages": [
      {
        "role": "user",
        "content": [{ "type": "text", "text": "用三句话介绍 ApiGo。" }]
      }
    ]
  }'
```

## Python 示例

```python theme={null}
from anthropic import Anthropic

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

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a concise assistant.",
    messages=[
        {
            "role": "user",
            "content": [{"type": "text", "text": "用三句话介绍 ApiGo。"}],
        }
    ],
)

print(response.content[0].text)
```

## Node.js 示例

```js theme={null}
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,
  system: "You are a concise assistant.",
  messages: [
    {
      role: "user",
      content: [{ type: "text", text: "用三句话介绍 ApiGo。" }]
    }
  ]
});

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

## 最佳实践

* `system` 是顶层字段，不要误塞进 `messages`
* 即使只是纯文本，也建议保留 Claude 原生 block 结构
* 把 `max_tokens` 设成显式值，避免默认值过小导致截断
