Developer Dashboard

Messages API Reference ​

Claude Fable 5.2: claude-fable-5-2 supports native /v1/messages, alongside Chat Completions and Responses. Send required max_tokens, preserve typed assistant content when continuing a conversation, and omit unsupported sampling or forced-tool controls. Adaptive thinking is always on; Anthropic's API effort default is high. Review the new all-account thinking-prefix checks before migrating a tool loop. See Fable's provider section, native request and response, and prices.

AvalAI exposes the Anthropic-compatible Messages schema for supported models from multiple providers, including direct Meta's muse-spark-1.3. Endpoint compatibility does not give a non-Anthropic model every Claude-specific feature or parameter. The Claude capabilities described below remain model-specific.

Direct Meta: Muse Spark 1.3 ​

muse-spark-1.3 supports /v1/messages and /v1/chat/completions, with partial /v1/responses support, from Tier 1. Send model, messages, and the required max_tokens; read typed content blocks rather than choices. With the Anthropic SDK, set the base URL to https://api.avalai.ir without /v1 and use your AvalAI key. Do not assume Claude-specific thinking, effort, caching, sampling, or refusal fields apply to Muse Spark.

Fee-inclusive USD input/cached-input/output rates are $1.4375/$0.1725/$4.8875 per million tokens, including an additional 15% billing-processing fee over official Meta rates. The separate muse-image-1.0 model is not supported on Messages; it supports only /v1/images/generations. See the Meta provider guide, pricing breakdown, and curl/Anthropic SDK examples with an illustrative response.

Anthropic Model Support ​

The Messages API provides access to Anthropic's models through the Claude API's v1/messages endpoint. This endpoint is part of AvalAI's multi-provider support, allowing you to interact with Anthropic models using their native API format. All Claude models including claude-sonnet-5, claude-opus-4-8, claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5, and other base model namespaces with smart routing are supported. The Messages API has full support for Claude Sonnet 5 and Claude Opus 4.8, including new capabilities such as role: "system" messages mid-conversation (preserves prompt cache hits) and the publicly documented stop_details object on refusal responses.

Endpoint ​

POST https://api.avalai.ir/v1/messages

Request Body ​

ParameterTypeRequiredDescription
modelstringYesExact ID of a model that supports Messages. See Anthropic or Meta Muse Spark; provider-specific options are not interchangeable.
messagesarrayYesArray of message objects representing the conversation history.
systemstringNoSystem instructions that prime the model for the conversation.
max_tokensintegerYesMaximum number of tokens to generate. Default varies by model.
temperaturenumberNoSampling temperature between 0 and 1. Higher values like 0.8 make output more random, while lower values like 0.2 make it more focused. Default is 1.
top_pnumberNoAlternative to temperature, nucleus sampling. Default is 1.
top_kintegerNoOnly sample from the top K options for each subsequent token. Default is -1 (disabled).
streambooleanNoIf set to true, partial message deltas will be sent. Default is false.
stop_sequencesarrayNoCustom text sequences that will cause the model to stop generating.
metadataobjectNoOptional metadata to include in the response.

The table describes the Messages API surface, not universal parameter support. Check the selected provider/model before sending optional sampling, thinking, caching, or metadata controls.

Message Object ​

Each message in the messages array should have the following structure:

ParameterTypeRequiredDescription
rolestringYesThe role of the message author. One of: user or assistant.
contentstring or arrayYesThe content of the message. Can be a string or an array of content blocks when using multimodal inputs.

Examples ​

Basic Message Completion ​

bash
curl https://api.avalai.ir/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $AVALAI_API_KEY" \
  -d '{
  "model": "anthropic.claude-sonnet-4-20250514-v1:0",
  "messages": [
    {
      "role": "user",
      "content": "Hello! Can you help me understand quantum computing?"
    }
  ],
  "max_tokens": 1024
}'
python
from anthropic import Anthropic

client = Anthropic(
    api_key="AVALAI_API_KEY",
    base_url="https://api.avalai.ir",  # AvalAI API endpoint without /v1
)

response = client.messages.create(
    model="anthropic.claude-sonnet-4-20250514-v1:0",
    messages=[
        {
            "role": "user",
            "content": "Hello! Can you help me understand quantum computing?",
        }
    ],
    max_tokens=1024,
)

print(response.content)
javascript
import { Anthropic } from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.AVALAI_API_KEY,
  baseURL: "https://api.avalai.ir", // AvalAI API endpoint without /v1
});

const response = await client.messages.create({
  model: "anthropic.claude-sonnet-4-20250514-v1:0",
  messages: [
    {
      role: "user",
      content: "Hello! Can you help me understand quantum computing?",
    },
  ],
  max_tokens: 1024,
});

console.log(response.content);
go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/anthropic/anthropic-sdk-go"
)

func main() {
	client := anthropic.NewClient(
		anthropic.WithAPIKey(os.Getenv("AVALAI_API_KEY")),
		anthropic.WithBaseURL("https://api.avalai.ir"),
	)

	resp, err := client.Messages.Create(context.Background(), &anthropic.MessagesRequest{
		Model: "anthropic.claude-sonnet-4-20250514-v1:0",
		Messages: []anthropic.Message{
			{
				Role:    "user",
				Content: "Hello! Can you help me understand quantum computing?",
			},
		},
		MaxTokens: 1024,
	})

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	fmt.Println(resp.Content)
}
php
<?php
// PHP Example for Messages API via AvalAI

$apiKey = getenv('AVALAI_API_KEY'); // Or replace with your key directly
$apiUrl = 'https://api.avalai.ir/v1/messages';

$data = [
  'model' => 'anthropic.claude-sonnet-4-20250514-v1:0',
  'messages' => [
    ['role' => 'user', 'content' => 'Hello! Can you help me understand quantum computing?']
  ],
  'max_tokens' => 1024
];

$jsonData = json_encode($data);

$ch = curl_init($apiUrl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Content-Type: application/json',
  'x-api-key: ' . $apiKey,
  'Content-Length: ' . strlen($jsonData)
]);

$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "cURL Error #:" . $err;
} elseif ($httpcode >= 400) {
  echo "HTTP Error: " . $httpcode . "\n";
  echo $response;
} else {
  $responseData = json_decode($response, true);
  echo "Assistant: " . $responseData['content'][0]['text'] . "\n";
}
?>

Response Format ​

json
{
  "id": "msg_01xyzabcdef",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Quantum computing is a fascinating field that uses principles of quantum mechanics to process information in ways that classical computers cannot. Instead of using bits that are either 0 or 1, quantum computers use quantum bits or 'qubits' that can exist in multiple states simultaneously due to a quantum property called superposition..."
    }
  ],
  "model": "anthropic.claude-sonnet-4-20250514-v1:0",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 15,
    "output_tokens": 75
  }
}

Response Parameters ​

ParameterTypeDescription
idstringA unique identifier for the message.
typestringThe object type, which is always "message".
rolestringThe role of the message author, which is "assistant" for responses.
contentarrayAn array of content blocks, typically containing text.
modelstringThe model used for the message generation.
stop_reasonstringThe reason why the model stopped generating tokens. Can be "end_turn", "max_tokens", "stop_sequence", or other values.
stop_sequencestring or nullIf the model stopped because it produced a stop sequence, this field contains that sequence. Otherwise null.
usageobjectAn object containing token usage information.

Content Block ​

ParameterTypeDescription
typestringThe type of content block. Currently "text" or "image".
textstringThe text content if the type is "text".

Usage Object ​

ParameterTypeDescription
input_tokensintegerThe number of tokens used in the input.
output_tokensintegerThe number of tokens used in the output.

Streaming ​

To receive incremental model responses, set stream: true in your request:

javascript
const stream = await client.messages.create({
  model: "anthropic.claude-sonnet-4-20250514-v1:0",
  messages: [
    { role: "user", content: "Write a story about a quantum computer." },
  ],
  stream: true,
  max_tokens: 1024,
});

for await (const chunk of stream) {
  if (
    chunk.type === "content_block_delta" &&
    chunk.delta.type === "text_delta"
  ) {
    process.stdout.write(chunk.delta.text || "");
  }
}

Error Handling ​

The API may return various error codes:

Status CodeDescription
400Bad Request - Your request is invalid.
401Unauthorized - Your API key is wrong.
403Forbidden - You don't have permission to access this resource.
404Not Found - The specified resource could not be found.
429Too Many Requests - You have exceeded your rate limit.
500Internal Server Error - We had a problem with our server.

For more information on handling errors, see the Error Handling guide.

Multi-provider Support ​

As of June 2025, the AvalAI platform supports using the Anthropic Messages API format to access models from multiple providers, including:

  • Anthropic (Claude models)
  • OpenAI
  • AWS Bedrock
  • Vertex AI
  • Gemini
  • MiniMax (including minimax-m3 with full support for native thinking blocks and tool use)

This unified API approach allows you to use the same code structure to access models from different providers while maintaining compatibility with Anthropic's client libraries.