# Messages

## Messages

> Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.\
> \
> The Messages API can be used for either single queries or stateless multi-turn conversations.

```json
{"openapi":"3.1.0","info":{"title":"Default module","version":"1.0.0"},"tags":[{"name":"Messages"}],"servers":[{"url":"https://llm.onerouter.pro","description":"正式环境"}],"security":[],"paths":{"/v1/messages":{"post":{"summary":"Messages","deprecated":false,"description":"Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.\n\nThe Messages API can be used for either single queries or stateless multi-turn conversations.","tags":["Messages"],"parameters":[{"name":"x-api-key","in":"header","description":"Your unique API key for authentication.","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string","description":"The model that will complete your prompt."},"messages":{"type":"array","items":{"type":"object","properties":{"role":{"type":"string"},"content":{"type":"string"}}},"description":"Our models are trained to operate on alternating user and assistant conversational turns. When creating a new Message, you specify the prior conversational turns with the messages parameter, and the model then generates the next Message in the conversation. Consecutive user or assistant turns in your request will be combined into a single turn.\n\nEach input message must be an object with a role and content. You can specify a single user-role message, or you can include multiple user and assistant messages.\n\nIf the final message uses the assistant role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response."},"max_tokens":{"type":"integer","description":"The maximum number of tokens to generate before stopping.","minimum":1},"stop_sequences":{"type":"array","items":{"type":"string"},"description":"Custom text sequences that will cause the model to stop generating.\n\nOur models will normally stop when they have naturally completed their turn, which will result in a response stop_reason of \"end_turn\".\n\nIf you want the model to stop generating when it encounters custom strings of text, you can use the stop_sequences parameter. If the model encounters one of the custom sequences, the response stop_reason value will be \"stop_sequence\" and the response stop_sequence value will contain the matched stop sequence."},"stream":{"type":"boolean","description":"Whether to incrementally stream the response using server-sent events."},"system":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string"},"type":{"type":"string"}}},"description":"A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role."},"temperature":{"type":"number","description":"Amount of randomness injected into the response.\n\n","default":1,"minimum":0,"maximum":1},"thinking":{"type":"object","properties":{"type":{"type":"string"}},"description":"Configuration for enabling Claude's extended thinking.\n\nWhen enabled, responses include thinking content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your max_tokens limit."},"tool_choice":{"type":"object","properties":{"type":{"type":"string"}},"required":["type"],"description":"How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all.\nThe model will automatically decide whether to use tools."},"tools":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"},"input_schema":{"type":"object","properties":{"type":{"type":"string"},"properties":{"type":"object","properties":{"ticker":{"type":"object","properties":{"type":{"type":"string"},"description":{"type":"string"}},"required":["type","description"]}},"required":["ticker"]},"required":{"type":"array","items":{"type":"string"}}},"required":["type","properties","required"]}}},"description":"Definitions of tools that the model may use."},"top_k":{"type":"number","description":"Only sample from the top K options for each subsequent token.","minimum":0},"top_p":{"type":"number","description":"Use nucleus sampling.","minimum":0,"maximum":1}},"required":["model","messages","max_tokens"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string"},"id":{"type":"string"},"type":{"type":"string"},"role":{"type":"string"},"content":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string"},"text":{"type":"string"}}}},"stop_reason":{"type":"string"},"stop_sequence":{"type":"null"},"usage":{"type":"object","properties":{"input_tokens":{"type":"integer"},"cache_creation_input_tokens":{"type":"integer"},"cache_read_input_tokens":{"type":"integer"},"output_tokens":{"type":"integer"}},"required":["input_tokens","cache_creation_input_tokens","cache_read_input_tokens","output_tokens"]}},"required":["model","id","type","role","content","stop_reason","stop_sequence","usage"]}}},"headers":{}}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infronai.gitbook.io/docs/api-reference/anthropic-claude-api/messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
