> For clean Markdown of any page, append `.md` to the page URL.
> Documentation index: https://you.com/docs/llms.txt (section indexes: append `/llms.txt` to any section URL).
> Search these docs: Docs MCP at https://you.com/docs/_mcp/server (`searchDocs`, no API key).
> Call live You.com APIs: Product MCP at https://api.you.com/mcp (keyless `?profile=free` exposes `you-search` and `you-discover`. Research and finance use `/mcp/research`, `/mcp/finance`, or `?tools=` on `/mcp`). To pick an API or integration path, call `you-discover` on that server instead of guessing.
> OpenAPI: https://you.com/docs/openapi.json—auth header `X-API-Key`, env `YDC_API_KEY`.

# Create Message

POST https://api.you.com/v1/messages
Content-Type: application/json

Anthropic-compatible Messages. Send a `model` from `GET /v1/models`, a `max_tokens` limit, and a list of `messages`. Declaring Anthropic's `web_search_*` server tool makes the router run You.com web searches and return `server_tool_use` and `web_search_tool_result` blocks.

Reference: https://you.com/docs/api-reference/inference-router/create-message

## Authentication

- `Authorization` header (bearer token, required) — Your You.com API key, sent as `Authorization: Bearer <key>`. Get a key in the ["Get your API key" section of the documentation](https://you.com/docs/quickstart#get-your-api-key).

## Request

### Headers

- `x-request-id` (string, optional) — A client-chosen request ID for tracing. The router generates one when the header is absent or invalid, and returns it in the response.
- `x-session-id` (string, optional) — A conversation identifier of up to 256 characters. Requests that share a session ID are kept together where possible.
- `anthropic-version` (string, optional) — The Anthropic API version, such as `2023-06-01`. Sending this header selects the Anthropic response format.

### Body (application/json)

This endpoint expects a MessageRequest.

- `model` (string, required) — A model ID from `GET /v1/models`.
- `max_tokens` (integer, required) — Maximum tokens to generate. Per-model limits are published as `max_tokens` in `GET /v1/models`.
- `messages` (list of MessageRequestMessagesItems, required) — The conversation so far, in Anthropic Messages format.
- `system` (MessageRequestSystem, optional) — A system prompt, as a string or an array of text blocks.
- `stream` (boolean, optional) — Stream the response as server-sent events.
- `temperature` (double, optional) — Sampling temperature. When omitted, the router applies the model vendor's reference value, where one is configured.
- `top_p` (double, optional) — Nucleus sampling probability. When omitted, the router applies the model vendor's reference value, where one is configured.
- `top_k` (integer, optional) — Sample only from the top K tokens.
- `stop_sequences` (list of string, optional) — Sequences where the model stops generating.
- `metadata` (map from string to any, optional)
- `thinking` (map from string to any, optional) — Extended thinking configuration.
- `output_config` (map from string to any, optional) — Output configuration, such as effort and a JSON schema format.
- `tool_choice` (map from string to any, optional) — How the model uses tools.
- `tools` (list of MessageRequestToolsItems, optional) — Tools the model may call. Declare one Anthropic `web_search_*` server tool for router-run web search.

## Response

### 200

A message, or a stream of Anthropic server-sent events when `stream` is `true`.

- `id` (string, optional)
- `type` (enum, optional)
  - Allowed values: `message`
- `role` (enum, optional)
  - Allowed values: `assistant`
- `model` (string, optional)
- `content` (list of map from string to any, optional) — Content blocks. A web search request adds `server_tool_use` and `web_search_tool_result` blocks for each search the router ran.
- `stop_reason` (string, optional, nullable)
- `stop_sequence` (string, optional, nullable)
- `usage` (MessageResponseUsage, optional)

## Errors

### 400 Bad Request Error

An error in Anthropic format.

- `type` (enum, required)
  - Allowed values: `error`
- `error` (AnthropicErrorResponseError, required)

### 401 Unauthorized Error

An error in Anthropic format.

- `type` (enum, required)
  - Allowed values: `error`
- `error` (AnthropicErrorResponseError, required)

### 403 Forbidden Error

An error in Anthropic format.

- `type` (enum, required)
  - Allowed values: `error`
- `error` (AnthropicErrorResponseError, required)

### 429 Too Many Requests Error

An error in Anthropic format.

- `type` (enum, required)
  - Allowed values: `error`
- `error` (AnthropicErrorResponseError, required)

### 503 Service Unavailable Error

An error in Anthropic format.

- `type` (enum, required)
  - Allowed values: `error`
- `error` (AnthropicErrorResponseError, required)

## Types

### MessageRequestMessagesItems

- `role` (enum, required)
  - Allowed values: `user`, `assistant`
- `content` (MessageRequestMessagesItemsContent, required)

### MessageRequestSystem

A system prompt, as a string or an array of text blocks.

- string
- list of map from string to any

### MessageRequestToolsItems

- AnthropicTool: AnthropicTool
- AnthropicWebSearchTool: AnthropicWebSearchTool

### MessageResponseUsage

- `input_tokens` (integer, optional)
- `output_tokens` (integer, optional)
- `cache_creation_input_tokens` (integer, optional)
- `cache_read_input_tokens` (integer, optional)

### AnthropicErrorResponseError

- `type` (string, required) — One of `invalid_request_error`, `authentication_error`, `permission_error`, `not_found_error`, `request_too_large`, `rate_limit_error`, or `overloaded_error`.
- `message` (string, required) — A description of the error.

### MessageRequestMessagesItemsContent

- string
- list of map from string to any

### AnthropicTool

- `name` (string, required)
- `input_schema` (map from string to any, required)
- `description` (string, optional)

### AnthropicWebSearchTool

Anthropic's versioned web search server tool. The router serves it with You.com search. Only one is allowed per request.

- `type` (string, required) — A versioned type such as `web_search_20250305`.
- `name` (enum, required)
  - Allowed values: `web_search`
- `max_uses` (integer, optional) — Maximum search rounds. A round can run several searches in parallel, so a request can search more than `max_uses` times.
- `blocked_domains` (list of string, optional) — Domains to leave out of results.
- `user_location` (AnthropicWebSearchToolUserLocation, optional) — Where the user is. The router uses `country`.

### AnthropicWebSearchToolUserLocation

Where the user is. The router uses `country`.

- `country` (string, optional) — Two-letter ISO 3166-1 alpha-2 country code.

## Examples

**Request**

```json
{
  "model": "string",
  "max_tokens": 1,
  "messages": [
    {
      "role": "user",
      "content": "string"
    }
  ]
}
```

**Response**

```json
{
  "id": "string",
  "type": "message",
  "role": "assistant",
  "model": "string",
  "content": [
    {}
  ],
  "stop_reason": "string",
  "stop_sequence": "string",
  "usage": {
    "input_tokens": 1,
    "output_tokens": 1,
    "cache_creation_input_tokens": 1,
    "cache_read_input_tokens": 1
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.you.com/v1/messages"

payload = {
    "model": "string",
    "max_tokens": 1,
    "messages": [
        {
            "role": "user",
            "content": "string"
        }
    ]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.you.com/v1/messages';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"string","max_tokens":1,"messages":[{"role":"user","content":"string"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.you.com/v1/messages"

	payload := strings.NewReader("{\n  \"model\": \"string\",\n  \"max_tokens\": 1,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"string\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.you.com/v1/messages")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"string\",\n  \"max_tokens\": 1,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"string\"\n    }\n  ]\n}")
  .asString();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.you.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"string\",\n  \"max_tokens\": 1,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"string\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "string",
  "max_tokens": 1,
  "messages": [
    [
      "role": "user",
      "content": "string"
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.you.com/v1/messages")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```