Claude Sonnet 5 Serverless API
Agentic coding, debugging and reasoning with 1M-token context.
API Format: Anthropic Claude
This model uses Anthropic Claude request/response format.
POST /v2/claude-sonnet-5 · submit + poll 1# pip install "segmind>=1.1.0"
2# export SEGMIND_API_KEY="YOUR_API_KEY"
3import segmind
4
5payload = {
6 "instruction": "You are a helpful assistant.",
7 "messages": [
8 {
9 "role": "user",
10 "content": [
11 {
12 "type": "text",
13 "text": "What's in this image?"
14 },
15 {
16 "type": "image",
17 "source": {
18 "type": "base64",
19 "media_type": "image/jpeg",
20 "data": "iVBORw0KGgoAAAANSUhEUgA..."
21 }
22 }
23 ]
24 }
25 ]
26,
27 "response_format": {
28 "type": "json_schema",
29 "json_schema": {
30 "name": "answer",
31 "strict": True,
32 "schema": {
33 "type": "object",
34 "properties": {"answer": {"type": "string"}},
35 "required": ["answer"],
36 "additionalProperties": False
37 }
38 }
39 }
40}
41
42# Async chat (v2): submit to the queue, block until COMPLETED.
43reply = segmind.chat("claude-sonnet-5", **payload)
44print(reply.text)
45
46# --- Or get a handle (track request_id, control the poll cadence) ---
47job = segmind.submit_chat("claude-sonnet-5", **payload)
48print(job.request_id) # available immediately
49reply = job.wait(timeout=600)
50print(reply.text) 1# pip install "segmind>=1.1.0"
2# export SEGMIND_API_KEY="YOUR_API_KEY"
3import segmind
4
5payload = {
6 "instruction": "You are a helpful assistant.",
7 "messages": [
8 {
9 "role": "user",
10 "content": [
11 {
12 "type": "text",
13 "text": "What's in this image?"
14 },
15 {
16 "type": "image",
17 "source": {
18 "type": "base64",
19 "media_type": "image/jpeg",
20 "data": "iVBORw0KGgoAAAANSUhEUgA..."
21 }
22 }
23 ]
24 }
25 ]
26,
27 "response_format": {
28 "type": "json_schema",
29 "json_schema": {
30 "name": "answer",
31 "strict": True,
32 "schema": {
33 "type": "object",
34 "properties": {"answer": {"type": "string"}},
35 "required": ["answer"],
36 "additionalProperties": False
37 }
38 }
39 }
40}
41
42# Async chat (v2): submit to the queue, block until COMPLETED.
43reply = segmind.chat("claude-sonnet-5", **payload)
44print(reply.text)
45
46# --- Or get a handle (track request_id, control the poll cadence) ---
47job = segmind.submit_chat("claude-sonnet-5", **payload)
48print(job.request_id) # available immediately
49reply = job.wait(timeout=600)
50print(reply.text)API Endpoint
POST https://api.segmind.com/v1/claude-sonnet-5Parameters
messagesrequiredobject[]Array of message objects with role and content array. Images must be base64 encoded with media_type.
rolerequiredstringRole of the message sender
"user""assistant"contentrequiredarrayArray of content blocks (text or image)
instructionoptionalstringSystem instruction that guides the model's behavior (replaces system message).
response_formatoptionalobjectOptional JSON Schema for structured output; list every property in required and set additionalProperties false (json_object unsupported). Use for machine-readable results, omit for plain text.
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-sonnet-5",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 56,
"output_tokens": 31
}
}With response_format
The envelope is unchanged: your JSON arrives as a string in the same field, which you parse yourself. Structured outputs guide
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "{\"answer\":\"Paris\"}"
}
],
"model": "claude-sonnet-5",
"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.
Asynchronous requests (v2)
Use Async for video, long-running (>~60s), or high-concurrency workloads; Sync is simplest for fast image & LLM calls. Async submits a request and you poll it to completion.
- 1
POST /v2/claude-sonnet-5Submit — returns request_id, status_url, response_url
- 2
GET /v2/requests/{id}/statusPoll — until COMPLETED or FAILED
- 3
GET /v2/requests/{id}Result — final response body
Status states
- A FAILED request is served as HTTP 422 — the body still carries the error detail.
- An unknown or expired request_id returns HTTP 404.
- Results are retained for 1 hour, then expire.
- Content / RAI blocks surface as FAILED, not a separate state.
- Track completion by polling the status endpoint.
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 — including a response_format this model does not accept, or a json_schema sent without a schema object
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