Claude 4 Sonnet

Claude 4 excels in advanced coding and multi-step reasoning, transforming complex tasks into manageable solutions.

~8.86s
~$0.007

API Format: Anthropic Claude

This model uses Anthropic Claude request/response format.

 1import requests
 2
 3url = "https://api.segmind.com/v1/claude-4-sonnet"
 4
 5headers = {
 6    "Authorization": "Bearer YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "instruction": "You are a helpful assistant.",
12    "messages": [
13        {
14            "role": "user",
15            "content": [
16                {
17                    "type": "text",
18                    "text": "What's in this image?"
19                },
20                {
21                    "type": "image",
22                    "source": {
23                        "type": "base64",
24                        "media_type": "image/jpeg",
25                        "data": "iVBORw0KGgoAAAANSUhEUgA..."
26                    }
27                }
28            ]
29        }
30    ]
31}
32
33response = requests.post(url, json=data, headers=headers)
34print(response.json())

API Endpoint

POST https://api.segmind.com/v1/claude-4-sonnet

Parameters

messagesrequired
object[]

Array of message objects with role and content array. Images must be base64 encoded with media_type.

Array items:
rolerequired
string

Role of the message sender

Allowed values :
"user""assistant"
contentrequired
array

Array of content blocks (text or image)

instructionoptional
string

System instruction that guides the model's behavior (replaces system message).

Response Format

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "I can see a beautiful sunset over the ocean with vibrant orange and pink hues in the sky."
    }
  ],
  "model": "claude-4-sonnet",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 56,
    "output_tokens": 31
  }
}

Image Input Format

Important: Anthropic Claude Format

Images must be base64 encoded in the source.data field with media_type specified

This model supports vision capabilities. You can include images in your requests.

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid message format or parameters

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out