You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`model`| string | Yes | The model that will complete your prompt. Example: `claude-3-7-sonnet-20250219`. |
24
-
|`messages`| array | Yes | A list of input messages comprising the conversation so far. See [The Message Object](https://www.google.com/search?q=%23the-message-object) below. |
25
-
|`max_tokens`| integer | Yes | The maximum number of tokens to generate. Different models have different maximums. |
26
-
|`system`| string or array | No | A system prompt to provide context and instructions to Claude, such as specifying a role or goal. |
27
-
|`metadata`| object | No | An object for metadata, such as a `user_id`, to help detect abuse. Do not include any personally identifying information. |
28
-
|`stop_sequences`| array | No | Custom text sequences that will cause the model to stop generating. |
29
-
|`stream`| boolean | No | If set, the response will be incrementally streamed using server-sent events. Defaults to `false`. |
30
-
|`temperature`| number | No | The amount of randomness injected into the response, ranging from `0.0` to `1.0`. Defaults to `1.0`. |
31
-
|`top_p`| number | No | Use nucleus sampling. The model considers tokens with `top_p` probability mass. Should alter `temperature` or `top_p`, but not both. |
32
-
|`top_k`| integer | No | Only sample from the top K options for each subsequent token. Recommended for advanced use cases. |
33
-
|`tools`| array | No | A list of tools the model may use. See [The Tool Object](https://www.google.com/search?q=%23the-tool-object) below. |
34
-
|`tool_choice`| object | No | Controls how the model should use the provided tools. Can be `auto`, `any`, `tool`, or `none`. |
|`model`| string | Yes | The model that will complete your prompt. Example: `claude-3-7-sonnet-20250219`. |
24
+
|`messages`| array | Yes | A list of input messages comprising the conversation so far. See [The Message Object](https://www.google.com/search?q=%23the-message-object) below. |
25
+
|`max_tokens`| integer | Yes | The maximum number of tokens to generate. Different models have different maximum values for this parameter. |
26
+
|`system`| string or array | No | A system prompt to provide context and instructions to Claude, such as specifying a role or goal. |
27
+
|`metadata`| object | No | An object for metadata, such as a `user_id`, to help detect abuse. Do not include any personally identifying information. |
28
+
|`stop_sequences`| array | No | Custom text sequences that will cause the model to stop generating. |
29
+
|`stream`| boolean | No | If set, the response will be incrementally streamed using server-sent events. Defaults to `false`. |
30
+
|`temperature`| number | No | The amount of randomness injected into the response, ranging from `0.0` to `1.0`. Defaults to `1.0`. |
31
+
|`thinking`| object | No | Configuration for enabling Claude's extended thinking process, which shows reasoning steps before the final answer. |
32
+
|`top_p`| number | No | Use nucleus sampling. The model considers tokens with `top_p` probability mass. You should alter `temperature` or `top_p`, but not both. |
33
+
|`top_k`| integer | No | Only sample from the top K options for each subsequent token. Recommended for advanced use cases only. |
34
+
|`tools`| array | No | A list of tools the model may use. See [The Tool Object](https://www.google.com/search?q=%23the-tool-object) below. |
35
+
|`tool_choice`| object | No | Controls how the model should use tools. Can be `{"type": "auto"}`, `{"type": "any"}`, `{"type": "tool", "name": "tool_name"}` or `{"type": "none"}`. |
36
+
|`service_tier`| string | No | Can be set to `auto` or `standard_only` to determine whether to use priority capacity. |
35
37
36
38
#### The Message Object
37
39
38
-
The `messages` array consists of message objects, where each object has a `role` and `content`. Models are trained on alternating `user` and `assistant` turns.
40
+
The `messages` array consists of message objects, where each object has a `role` and `content`. Models are trained on alternating `user` and `assistant`conversational turns.
|`role`| string | Yes | The role of the message author. Must be either `user` or `assistant`. |
43
-
|`content`| string or array | Yes | The content of the message. This can be a simple string or an array of content blocks for multimodal input (e.g., text and images). |
|`role`| string | Yes | The role of the message author. Must be either `user` or `assistant`. |
45
+
|`content`| string or array | Yes | The content of the message. This can be a simple string or an array of content blocks for multimodal input. |
44
46
45
47
**Content Blocks:** For multimodal input, the `content` array can contain different types of blocks.
46
48
47
49
-**`text`**: A block with a `type` of "text" and a `text` field containing the string.
48
-
-**`image`**: A block with a `type` of "image" and a `source` object. The sourcemust specify its`type`(e.g., "base64"), `media_type` (e.g., "image/jpeg"), and `data`.
49
-
-**`tool_result`**: A block used to return the output of a tool back to the model. It includes the `tool_use_id`, `content`, and an optional `is_error` flag.
50
+
-**`image`**: Starting with Claude 3 models, you can send image content blocks. The `source` object must specify a`type`of "base64", a `media_type` (`image/jpeg`, `image/png`, `image/gif`, or `image/webp`), and the`data`.
51
+
-**`tool_result`**: A block used to return the output of a tool back to the model. It includes the `tool_use_id`, the `content` from the tool's execution, and an optional `is_error` flag.
50
52
51
53
#### The Tool Object
52
54
53
55
The `tools` array allows you to define client-side tools the model can call.
|`id`| string | A unique identifier for the message object. |
70
+
|`type`| string | The object type, which is always `message`. |
71
+
|`role`| string | The role of the author, which is always `assistant`. |
72
+
|`content`| array | An array of content blocks generated by the model (e.g., `text` or `tool_use`). |
73
+
|`model`| string | The model that handled the request. |
74
+
|`stop_reason`| string | The reason the model stopped generating tokens. Can be `end_turn`, `max_tokens`, `stop_sequence`, `tool_use`, `pause_turn`, or `refusal`. |
75
+
|`stop_sequence`| string | If the model was stopped by a custom stop sequence, this field will contain which sequence was generated. Can be null. |
76
+
|`usage`| object | An object containing token usage statistics. See [The Usage Object](https://www.google.com/search?q=%23the-usage-object). |
77
+
78
+
#### Streaming Response (200 OK)
79
+
80
+
If `stream: true` is set, the API streams back a sequence of server-sent events. The response is a series of JSON events that incrementally build the complete message object.
81
+
82
+
According to the documentation, the `stop_reason` provides insight into the stream's state: in the initial `message_start` event, the `stop_reason` field will be `null`. In all other events, it will be non-null once the stopping condition is known.
75
83
76
84
#### The Usage Object
77
85
78
86
The `usage` object details billing and rate-limit token counts.
0 commit comments