Create Message
curl --request POST \
--url https://api.electronhub.ai/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{
"content": "<string>"
}
],
"max_tokens": 123,
"temperature": 0.5,
"top_p": 123,
"top_k": 123,
"stream": false,
"system": "<string>",
"tools": [
{
"name": "<string>",
"description": "<string>",
"input_schema": {},
"type": "<string>",
"strict": true,
"defer_loading": true,
"eager_input_streaming": true
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 123
},
"betas": [
"<string>"
],
"context_management": {},
"output_config": {},
"metadata": {}
}
'import requests
url = "https://api.electronhub.ai/v1/messages"
payload = {
"model": "claude-sonnet-4-5-20250929",
"messages": [{ "content": "<string>" }],
"max_tokens": 123,
"temperature": 0.5,
"top_p": 123,
"top_k": 123,
"stream": False,
"system": "<string>",
"tools": [
{
"name": "<string>",
"description": "<string>",
"input_schema": {},
"type": "<string>",
"strict": True,
"defer_loading": True,
"eager_input_streaming": True
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 123
},
"betas": ["<string>"],
"context_management": {},
"output_config": {},
"metadata": {}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'claude-sonnet-4-5-20250929',
messages: [{content: '<string>'}],
max_tokens: 123,
temperature: 0.5,
top_p: 123,
top_k: 123,
stream: false,
system: '<string>',
tools: [
{
name: '<string>',
description: '<string>',
input_schema: {},
type: '<string>',
strict: true,
defer_loading: true,
eager_input_streaming: true
}
],
thinking: {type: 'enabled', budget_tokens: 123},
betas: ['<string>'],
context_management: {},
output_config: {},
metadata: {}
})
};
fetch('https://api.electronhub.ai/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.electronhub.ai/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' => 'claude-sonnet-4-5-20250929',
'messages' => [
[
'content' => '<string>'
]
],
'max_tokens' => 123,
'temperature' => 0.5,
'top_p' => 123,
'top_k' => 123,
'stream' => false,
'system' => '<string>',
'tools' => [
[
'name' => '<string>',
'description' => '<string>',
'input_schema' => [
],
'type' => '<string>',
'strict' => true,
'defer_loading' => true,
'eager_input_streaming' => true
]
],
'thinking' => [
'type' => 'enabled',
'budget_tokens' => 123
],
'betas' => [
'<string>'
],
'context_management' => [
],
'output_config' => [
],
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.electronhub.ai/v1/messages"
payload := strings.NewReader("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"model": "<string>",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 123,
"output_tokens": 123
},
"stop_sequence": "<string>"
}API Reference
Messages API
Create a message with the Anthropic Messages format
POST
/
messages
Create Message
curl --request POST \
--url https://api.electronhub.ai/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{
"content": "<string>"
}
],
"max_tokens": 123,
"temperature": 0.5,
"top_p": 123,
"top_k": 123,
"stream": false,
"system": "<string>",
"tools": [
{
"name": "<string>",
"description": "<string>",
"input_schema": {},
"type": "<string>",
"strict": true,
"defer_loading": true,
"eager_input_streaming": true
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 123
},
"betas": [
"<string>"
],
"context_management": {},
"output_config": {},
"metadata": {}
}
'import requests
url = "https://api.electronhub.ai/v1/messages"
payload = {
"model": "claude-sonnet-4-5-20250929",
"messages": [{ "content": "<string>" }],
"max_tokens": 123,
"temperature": 0.5,
"top_p": 123,
"top_k": 123,
"stream": False,
"system": "<string>",
"tools": [
{
"name": "<string>",
"description": "<string>",
"input_schema": {},
"type": "<string>",
"strict": True,
"defer_loading": True,
"eager_input_streaming": True
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 123
},
"betas": ["<string>"],
"context_management": {},
"output_config": {},
"metadata": {}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'claude-sonnet-4-5-20250929',
messages: [{content: '<string>'}],
max_tokens: 123,
temperature: 0.5,
top_p: 123,
top_k: 123,
stream: false,
system: '<string>',
tools: [
{
name: '<string>',
description: '<string>',
input_schema: {},
type: '<string>',
strict: true,
defer_loading: true,
eager_input_streaming: true
}
],
thinking: {type: 'enabled', budget_tokens: 123},
betas: ['<string>'],
context_management: {},
output_config: {},
metadata: {}
})
};
fetch('https://api.electronhub.ai/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.electronhub.ai/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' => 'claude-sonnet-4-5-20250929',
'messages' => [
[
'content' => '<string>'
]
],
'max_tokens' => 123,
'temperature' => 0.5,
'top_p' => 123,
'top_k' => 123,
'stream' => false,
'system' => '<string>',
'tools' => [
[
'name' => '<string>',
'description' => '<string>',
'input_schema' => [
],
'type' => '<string>',
'strict' => true,
'defer_loading' => true,
'eager_input_streaming' => true
]
],
'thinking' => [
'type' => 'enabled',
'budget_tokens' => 123
],
'betas' => [
'<string>'
],
'context_management' => [
],
'output_config' => [
],
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.electronhub.ai/v1/messages"
payload := strings.NewReader("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\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(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"max_tokens\": 123,\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"top_k\": 123,\n \"stream\": false,\n \"system\": \"<string>\",\n \"tools\": [\n {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"input_schema\": {},\n \"type\": \"<string>\",\n \"strict\": true,\n \"defer_loading\": true,\n \"eager_input_streaming\": true\n }\n ],\n \"thinking\": {\n \"type\": \"enabled\",\n \"budget_tokens\": 123\n },\n \"betas\": [\n \"<string>\"\n ],\n \"context_management\": {},\n \"output_config\": {},\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"model": "<string>",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 123,
"output_tokens": 123
},
"stop_sequence": "<string>"
}Send a structured conversation to a model and receive an assistant message. Models trained for alternating turns expect
*Provide one of
Server tool result types (for example
On multi-turn requests, include the full previous assistant
user and assistant messages; a top-level system field sets standing instructions.
Create a message
POST /v1/messages
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes* | Bearer <api_key> |
x-api-key | Yes* | Alternative to Authorization |
Content-Type | Yes | application/json |
anthropic-version | No | Accepted when present (for example 2023-06-01) |
Authorization or x-api-key.
Body parameters
string
required
Model ID. Examples:
claude-sonnet-4-5-20250929, glm-5.3:dev.array
required
Input turns. Each item has
role and content.role:user,assistant, orsystem(mid-conversation system instruction; cannot be the first entry)content: string, or an array of content blocks (see below)
assistant, generation continues from that partial reply.integer
Maximum number of tokens to generate before stopping. Required by many Anthropic clients; omit only when the client supplies a default.
string | array
Standing system prompt for the whole conversation.
- string: plain text
- array: list of
{ "type": "text", "text": "...", "cache_control"?: { "type": "ephemeral", "ttl"?: "5m" \| "1h" } }blocks
messages[0].role = "system"; use this field instead.object
Extended thinking configuration.
type | Fields |
|---|---|
enabled | budget_tokens (required), optional display |
adaptive | optional budget_tokens, optional display |
disabled | none |
display is "summarized" or "omitted". When thinking is enabled, assistant content may include thinking blocks (with signature) before text / tool_use.array
Tools the model may call. Each custom tool:
name(string, required)description(string)input_schema(JSON Schema object)- optional:
cache_control,strict,defer_loading,eager_input_streaming,allowed_callers,input_examples
type (for example bash_20250124) and omit input_schema.object
How the model should use tools:
{ "type": "auto" }{ "type": "any" }{ "type": "tool", "name": "<tool_name>" }{ "type": "none" }
number
Sampling temperature. Range depends on the upstream model (commonly 0 to 1).
number
Nucleus sampling.
0 is ignored.integer
Top-k sampling.
0 is ignored.array
Custom strings that stop generation when emitted.
boolean
If
true, respond with server-sent events. Default false.object
Optional
{ "user_id": string } for abuse tracking. Opaque ID only; do not put PII.array
Anthropic beta feature flags. Accepted and forwarded when relevant.
object
Server-side context edits, for example:
{
"edits": [
{ "type": "clear_thinking_20251015", "keep": "all" }
]
}
object
Output controls such as
{ "effort": "low" | "medium" | "high" }.Content blocks
content may be a string (shorthand for one text block) or an array of blocks.
User / mid-conversation system
type | Fields | Notes |
|---|---|---|
text | text, optional cache_control | Primary text |
image | source | source.type: base64 (media_type, data) or url (url) |
document | source, optional title, context | PDF / text document input |
tool_result | tool_use_id, content, optional is_error, cache_control | Reply to a prior tool_use |
mid_conv_system | content (text blocks) | Structured mid-conversation system payload |
tool_addition / tool_removal | tool | Mid-conversation tool availability changes |
web_search_tool_result) are accepted as passthrough blocks.
Assistant
type | Fields | Notes |
|---|---|---|
text | text, optional cache_control | Visible reply |
tool_use | id, name, input, optional cache_control | Client tool call |
server_tool_use | id, name, input | Server-executed tool call |
thinking | thinking, signature | Prior-turn reasoning; echo unchanged on the next request |
redacted_thinking | data | Encrypted thinking; echo unchanged |
content array (including thinking blocks) so reasoning continuity is preserved.
Response
Non-streaming responses are Anthropic message objects:{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-5-20250929",
"content": [
{ "type": "text", "text": "..." }
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 20
}
}
stop_reason is typically end_turn, max_tokens, stop_sequence, or tool_use.
Errors use Anthropic’s envelope:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "..."
}
}
Example
curl https://api.electronhub.ai/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello"}
]
}'
import anthropic
client = anthropic.Anthropic(
api_key="YOUR_API_KEY",
base_url="https://api.electronhub.ai/v1",
)
message = client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.electronhub.ai/v1",
});
const message = await client.messages.create({
model: "claude-sonnet-4-5-20250929",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});
console.log(message.content);
Count tokens
POST /v1/messages/count_tokens
Estimate input tokens for a Messages request without running inference.
Body
Same shape as Create a message: at leastmodel and messages. system, tools, and related fields are included in the estimate when present.
Response
{
"input_tokens": 1234
}
Authorizations
Enter your API key (starts with 'ek-')
Body
application/json
Model ID
Example:
"claude-sonnet-4-5-20250929"
Conversation turns
Show child attributes
Show child attributes
Maximum tokens to generate
Required range:
0 <= x <= 1Top-level system prompt
Show child attributes
Show child attributes
Available options:
auto, any, none - Option 1
- Option 2
Show child attributes
Show child attributes
Ignored for models that do not support reasoning_effort
Available options:
none, minimal, low, medium, high, xhigh Response
200 - application/json
Success
Available options:
message Available options:
assistant - Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
Show child attributes
Show child attributes
Available options:
end_turn, max_tokens, stop_sequence, tool_use Show child attributes
Show child attributes
