典名词元典名词元首页
API 文档三方工具教程
AI 模型接口文本

文本生成(Claude)

POST/api/v1/messages

Header Parameters

Authorization*string

使用 Bearer Token 认证。 格式: Authorization: Bearer sk-xxxxxx

Request Body

application/json

model*string

模型名称,固定值: claude-opus-4-6 claude-opus-4-5-20251101 claude-haiku-4-5-20251001 claude-sonnet-4-5-20250929

messages*array<object>

对话消息数组(不包含 system 消息)

每条消息的 role 只能为 "user" 或 "assistant",且必须交替出现(第一条必须为 user)

[]?object
role*string

消息角色

Value in"system" | "user" | "assistant" | "tool"
content*string|array<object>

消息内容 支持字符串或内容块数组

max_tokens*integer

最大输出token数

system?string|array<string>

System prompt,字符串或内容块数组

stream?boolean

是否使用流式响应,默认 false

temperature?number

随机性控制 (0.0–1.0)

top_p?number

核采样 (0.0–1.0)

top_k?integer

Top-K 采样

stop_sequences?array<string>

停止词列表

[]?string
tools?array<object>

包含一个或多个工具对象的数组,供模型在 Function Calling 中调用。

[]?object
name?string

工具名称

description?string

该工具的描述是可选的,但强烈推荐。

input_schema?string

模型将在tool_use输出内容块中生成的工具输入形状的JSON模式。

tool_choice?object

工具选择策略。若需对某类问题强制指定工具调用方式(例如始终使用某工具或禁用所有工具),可设置此参数。

可选值:

auto

大模型自主选择工具策略。

none

若不希望进行工具调用,可设定tool_choice参数为none;

{"type": "function", "function": {"name": "the_function_to_call"}}

若希望强制调用某个工具,可设定tool_choice参数为{"type": "function", "function": {"name": "the_function_to_call"}},其中the_function_to_call是指定的工具函数名称。

type?string

类型,可选值 none、auto、any、tool

disable_parallel_tool_use?boolean
name?string

要使用的工具的名称。类型为tool时使用

thinking?object

扩展思考模式,格式:{"type": "enabled", "budget_tokens": 5000}

type?string

可选值 enabled、disenabled、adaptive

To turn on extended thinking, add a thinking object, with the type parameter set to enabled and the budget_tokens to a specified token budget for extended thinking. For Claude Opus 4.6 and Claude Sonnet 4.6, use type: "adaptive" instead. See Adaptive thinking for details. While type: "enabled" with budget_tokens is still functional on these models, it is deprecated and will be removed in a future release.

The budget_tokens parameter determines the maximum number of tokens Claude is allowed to use for its internal reasoning process. In Claude 4 and later models, this limit applies to full thinking tokens, and not to the summarized output. Larger budgets can improve response quality by enabling more thorough analysis for complex problems, although Claude may not use the entire budget allocated, especially at ranges above 32k.

budget_tokens?string

确定Claude可以用于其内部推理过程的令牌数量。更大的预算可以对复杂问题进行更彻底的分析,提高响应质量。

display?string

可选项 "summarized" or "omitted"

控制思维内容在响应中的显示方式。当设置为omitted时,思维会正常返回。当设置为summarized时,思维内容会被编辑,但会返回一个签名以实现多回合连续性。默认为摘要。

metadata?object

请求元数据,如 {"user_id": "user-123"}

user_id?string

An external identifier for the user who is associated with the request.

This should be a uuid, hash value, or other opaque identifier. Anthropic may use this id to help detect abuse. Do not include any identifying information such as name, email address, or phone number.

maxLength512

Response Body

application/json

curl -X POST "https://api.aa.com.cn/api/v1/messages" \  -H "Authorization: string" \  -H "Content-Type: application/json" \  -d '{    "model": "string",    "messages": [      {        "role": "system",        "content": "string"      }    ],    "max_tokens": 0,    "system": "string",    "stream": true,    "temperature": 0,    "top_p": 0,    "top_k": 0,    "stop_sequences": [      "string"    ],    "tools": [      {        "name": "string",        "description": "string",        "input_schema": "string"      }    ],    "tool_choice": {      "type": "string",      "disable_parallel_tool_use": true,      "name": "string"    },    " thinking": {      "type": "string",      "budget_tokens": "string",      "display": "string"    },    "metadata": {      "user_id": "string"    }  }'
{
  "id": "string",
  "type": "string",
  "role": "string",
  "model": "string",
  "content": [
    {
      "type": "string",
      "text": "string"
    }
  ],
  "stop_reason": "string",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}