典名词元DMTOKENSHome
API DocumentationThird-Party Tools Tutorial
AI Model APIText

Text Generation (Claude)

POST/api/v1/messages

Header Parameters

Authorization*string

Use Bearer Token authentication. Format: Authorization: Bearer sk-xxxxxx

Request Body

application/json

model*string

Model name, fixed values: claude-opus-4-6, claude-opus-4-5-20251101, claude-haiku-4-5-20251001, claude-sonnet-4-5-20250929

messages*array<object>

Array of conversation messages (excluding system messages). The role of each message must be either "user" or "assistant", and they must alternate (the first message must be "user").

[]?object
role*string

Message Role

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

Message content supports a string or an array of content blocks.

max_tokens*integer

Maximum Output Tokens

system?string|array<string>

System prompt, string or array of content blocks

stream?boolean

Whether to use streaming response, default false

temperature?number

Randomness Control (0.0–1.0)

top_p?number

Nucleus Sampling (0.0–1.0)

top_k?integer

Top-K Sampling

stop_sequences?array<string>

Stop Word List

[]?string
tools?array<object>

An array containing one or more tool objects for the model to invoke during Function Calling.

[]?object
name?string

Tool Name

description?string

The description of this tool is optional, but highly recommended.

input_schema?string

The JSON schema for the tool input shape that the model will generate in the tool_use output content block.

tool_choice?object

Tool selection strategy. Set this parameter to force a specific tool calling method for certain types of queries, such as always using a specific tool or disabling all tools. Optional values: auto: The model autonomously selects the tool. none: Set the tool_choice parameter to none if no tool calls are desired; {"type": "function", "function": {"name": "the_function_to_call"}}: To force a call to a specific tool, set the tool_choice parameter to {"type": "function", "function": {"name": "the_function_to_call"}}, where the_function_to_call is the name of the specified tool function.

type?string

Type, possible values: none, auto, any, tool

disable_parallel_tool_use?boolean
name?string

The name of the tool to use. Used when the type is tool.

thinking?object

Extended thinking mode, format: {"type": "enabled", "budget_tokens": 5000}

type?string

Optional values: enabled, disabled, 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

Determine the number of tokens Claude can use for its internal reasoning process. A larger budget enables more thorough analysis of complex problems, improving response quality.

display?string

Options "summarized" or "omitted". Controls how thinking content is displayed in the response. When set to omitted, thinking is returned normally. When set to summarized, the thinking content is edited, but a signature is returned for multi-turn continuity. Defaults to summarized.

metadata?object

Request metadata, such as {"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

Success

TypeScript Definitions

Use the response body type in TypeScript.

id*string

Unique object identifier.

type*string

For Messages, this is always "message".

role*string

Conversational role of the generated message.

This will always be "assistant".

model*string

The model that will complete your prompt.

content*array<object>

Content generated by the model.

[]?object
type?string
text?string
stop_reason*string

The reason that we stopped.

stop_sequence*null

Which custom stop sequence was generated, if any.

usage*object

Billing and rate-limit usage.

input_tokens*integer

The number of input tokens which were used.

output_tokens*integer

The number of output tokens which were used.

cache_creation_input_tokens?integer

The number of input tokens used to create the cache entry.

cache_read_input_tokens?integer

The number of input tokens read from the cache.

curl -X POST "https://api.ygw.ai/api/v1/messages" \  -H "Authorization: string" \  -H "Content-Type: application/json" \  -d '{    "model": "string",    "messages": [      {        "role": "system",        "content": "string"      }    ],    "max_tokens": 0  }'
{
  "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
  }
}