Claude 4 Sonnet
Claude 4 excels in advanced coding and multi-step reasoning, transforming complex tasks into manageable solutions.
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())
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
messages
requiredobject[]
Array of message objects with role and content array. Images must be base64 encoded with media_type.
role
requiredstring
Role of the message sender
"user"
"assistant"
content
requiredarray
Array of content blocks (text or image)
instruction
optionalstring
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.
Bad Request
Invalid message format or parameters
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Model or endpoint not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out