Anthropic Messages API
POST
/v1/messages
package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.mirapi.ai/v1/messages"
payload := strings.NewReader("{ \"model\": \"claude-3-opus-20240229\", \"messages\": [ { \"role\": \"user\", \"content\": [ { \"type\": \"text\", \"text\": \"example\", \"source\": { \"type\": \"base64\", \"media_type\": \"example\", \"data\": \"example\", \"url\": \"example\" }, \"id\": \"example\", \"name\": \"example\", \"input\": {}, \"tool_use_id\": \"example\", \"content\": \"example\" } ] } ], \"system\": [ {} ], \"max_tokens\": 1, \"temperature\": 1, \"top_p\": 1, \"top_k\": 1, \"stream\": true, \"stop_sequences\": [ \"example\" ], \"tools\": [ { \"name\": \"example\", \"description\": \"example\", \"input_schema\": {} } ], \"tool_choice\": { \"type\": \"auto\", \"name\": \"example\" }, \"thinking\": { \"type\": \"enabled\", \"budget_tokens\": 1 }, \"metadata\": { \"user_id\": \"example\" } }")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "") req.Header.Add("x-api-key", "") 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))
}const url = 'https://api.mirapi.ai/v1/messages';const options = { method: 'POST', headers: { 'anthropic-version': '', 'x-api-key': '', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"model":"claude-3-opus-20240229","messages":[{"role":"user","content":[{"type":"text","text":"example","source":{"type":"base64","media_type":"example","data":"example","url":"example"},"id":"example","name":"example","input":{},"tool_use_id":"example","content":"example"}]}],"system":[{}],"max_tokens":1,"temperature":1,"top_p":1,"top_k":1,"stream":true,"stop_sequences":["example"],"tools":[{"name":"example","description":"example","input_schema":{}}],"tool_choice":{"type":"auto","name":"example"},"thinking":{"type":"enabled","budget_tokens":1},"metadata":{"user_id":"example"}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.mirapi.ai/v1/messages \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'anthropic-version: ' \ --header 'x-api-key: ' \ --data '{ "model": "claude-3-opus-20240229", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "example", "source": { "type": "base64", "media_type": "example", "data": "example", "url": "example" }, "id": "example", "name": "example", "input": {}, "tool_use_id": "example", "content": "example" } ] } ], "system": [ {} ], "max_tokens": 1, "temperature": 1, "top_p": 1, "top_k": 1, "stream": true, "stop_sequences": [ "example" ], "tools": [ { "name": "example", "description": "example", "input_schema": {} } ], "tool_choice": { "type": "auto", "name": "example" }, "thinking": { "type": "enabled", "budget_tokens": 1 }, "metadata": { "user_id": "example" } }'Request in the Anthropic Claude Messages API format.
The anthropic-version header is required.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”anthropic-version
required
string
Anthropic API version
Example
x-api-key
string
Anthropic API key (optional — a Bearer token also works)
Example
Request Body
Section titled “Request Body”Media typeapplication/json
object
model
required
string
messages
required
Array<object>
object
role
required
string
content
required
One of:
string
Array<object>
object
type
string
text
string
source
object
type
string
media_type
string
data
string
url
string
id
string
name
string
input
object
tool_use_id
string
content
string
system
One of:
string
Array<object>
object
max_tokens
required
integer
temperature
number
top_p
number
top_k
integer
stream
boolean
stop_sequences
Array<string>
tools
Array<object>
object
name
string
description
string
input_schema
object
tool_choice
One of:
object
type
string
name
string
thinking
object
type
string
budget_tokens
integer
metadata
object
user_id
string
Examples
Responses
Section titled “Responses”Response created
Media typeapplication/json
object
id
string
type
string
role
string
content
Array<object>
object
type
string
text
string
model
string
stop_reason
string
usage
object
input_tokens
integer
output_tokens
integer
cache_creation_input_tokens
integer
cache_read_input_tokens
integer
Example
{ "type": "message", "role": "assistant", "stop_reason": "end_turn"}