curl --request POST \
--url https://api.myrouter.example/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'anthropic-version: <anthropic-version>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>"
}
],
"max_tokens": 2,
"stream": true,
"system": "<string>",
"stop_sequences": [
"<string>"
],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"tools": [
{}
],
"tool_choice": "<string>",
"metadata": {}
}
'import requests
url = "https://api.myrouter.example/anthropic/v1/messages"
payload = {
"model": "<string>",
"messages": [{ "content": "<string>" }],
"max_tokens": 2,
"stream": True,
"system": "<string>",
"stop_sequences": ["<string>"],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"tools": [{}],
"tool_choice": "<string>",
"metadata": {}
}
headers = {
"anthropic-version": "<anthropic-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<string>'}],
max_tokens: 2,
stream: true,
system: '<string>',
stop_sequences: ['<string>'],
temperature: 123,
top_p: 123,
top_k: 123,
tools: [{}],
tool_choice: '<string>',
metadata: {}
})
};
fetch('https://api.myrouter.example/anthropic/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.myrouter.example/anthropic/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
'content' => '<string>'
]
],
'max_tokens' => 2,
'stream' => true,
'system' => '<string>',
'stop_sequences' => [
'<string>'
],
'temperature' => 123,
'top_p' => 123,
'top_k' => 123,
'tools' => [
[
]
],
'tool_choice' => '<string>',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"anthropic-version: <anthropic-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.myrouter.example/anthropic/v1/messages"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.myrouter.example/anthropic/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.myrouter.example/anthropic/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"model": "<string>",
"stop_reason": "<string>",
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1,
"cache_read_tokens": 1,
"cache_write_tokens": 1,
"reasoning_tokens": 1
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}Create Anthropic-compatible message
Anthropic-compatible Messages invocation. Authorization Bearer is recommended; x-api-key is accepted only for SDK compatibility.
curl --request POST \
--url https://api.myrouter.example/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'anthropic-version: <anthropic-version>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>"
}
],
"max_tokens": 2,
"stream": true,
"system": "<string>",
"stop_sequences": [
"<string>"
],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"tools": [
{}
],
"tool_choice": "<string>",
"metadata": {}
}
'import requests
url = "https://api.myrouter.example/anthropic/v1/messages"
payload = {
"model": "<string>",
"messages": [{ "content": "<string>" }],
"max_tokens": 2,
"stream": True,
"system": "<string>",
"stop_sequences": ["<string>"],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"tools": [{}],
"tool_choice": "<string>",
"metadata": {}
}
headers = {
"anthropic-version": "<anthropic-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: '<string>',
messages: [{content: '<string>'}],
max_tokens: 2,
stream: true,
system: '<string>',
stop_sequences: ['<string>'],
temperature: 123,
top_p: 123,
top_k: 123,
tools: [{}],
tool_choice: '<string>',
metadata: {}
})
};
fetch('https://api.myrouter.example/anthropic/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.myrouter.example/anthropic/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'messages' => [
[
'content' => '<string>'
]
],
'max_tokens' => 2,
'stream' => true,
'system' => '<string>',
'stop_sequences' => [
'<string>'
],
'temperature' => 123,
'top_p' => 123,
'top_k' => 123,
'tools' => [
[
]
],
'tool_choice' => '<string>',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"anthropic-version: <anthropic-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.myrouter.example/anthropic/v1/messages"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.myrouter.example/anthropic/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.myrouter.example/anthropic/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 2,\n \"stream\": true,\n \"system\": \"<string>\",\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"model": "<string>",
"stop_reason": "<string>",
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1,
"cache_read_tokens": 1,
"cache_write_tokens": 1,
"reasoning_tokens": 1
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}{
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>"
},
"request_id": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Optional caller request id.
Anthropic API version.
Anthropic SDK-compatible API key header. Prefer Authorization: Bearer for MyRouter.
Body
Public MyRouter model id exposed through Anthropic-compatible API.
Anthropic-style input messages.
1Show child attributes
Show child attributes
Maximum output tokens.
x >= 1Whether to stream SSE events.
System prompt content.
Stop sequences.
Sampling temperature.
Nucleus sampling value.
Top-k sampling value.
Anthropic tool definitions.
Tool choice.
Customer metadata.
Response
Create Anthropic-compatible message response.
Message id.
Anthropic response type.
Assistant role.
Output content blocks.
Public MyRouter model id.
Why generation stopped.
Runtime usage facts, not invoice-grade charge evidence.
Show child attributes
Show child attributes