Loading…

API · Text

claude-sonnet-4-6 API

Text generation with a shared Topview Platform API key and USD wallet.

Playground · Markdown for agents

Authentication and model selection

Use your Topview Platform API key, not a provider key. Send Authorization: Bearer YOUR_PLATFORM_API_KEY. Claude also accepts x-api-key. GET https://platform-backend.topview.ai/v1/models lists enabled models. Model-restricted keys must allow anthropic/claude-sonnet-4-6. Select the model with model: "claude-sonnet-4-6". Keep API keys on your server.

Authentication and model selection
curl https://platform-backend.topview.ai/v1/models -H 'Authorization: Bearer YOUR_PLATFORM_API_KEY'

Request

POST /v1/messages. Text generation returns the response directly, or streams SSE; it does not use the image/video prediction submission and polling API.

Request
curl https://platform-backend.topview.ai/v1/messages \
  -H 'Authorization: Bearer YOUR_PLATFORM_API_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: unique_request_0001' \
  -d '{
  "model": "claude-sonnet-4-6",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 1024
}'

Parameters and limits

Required: model and messages (1–64 messages). max_tokens: integer 1–8192, default 1024. stream: boolean, default false. Maximum request JSON: 32 MiB; attachments total at most 20 MiB. Send the conversation history with every request. Use the top-level system field for system instructions. Optional fields: temperature, top_p, stop_sequences, thinking, output_config and cache_control. Model-specific parameter compatibility still applies. tools, tool_choice and metadata are accepted; at most 16 client-side function tools. Hosted tools, premium processing tiers and stored server-side conversations are not enabled.

Response and token usage

Read text blocks in content[].text and usage.input_tokens / usage.output_tokens. Tool calls appear as tool_use blocks. Cache usage may include cache_read_input_tokens and cache_creation_input_tokens.

Response and token usage
{
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [
    {
      "type": "text",
      "text": "Hello!"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 8,
    "output_tokens": 3
  }
}

Streaming and tools

Set stream: true and consume text/event-stream incrementally. Handle message_start, content_block_start, content_block_delta, message_delta and message_stop. Assemble tool input JSON deltas before running the tool. Function tools run in your application: execute the requested function, append the tool result and send the next turn. A stream disconnect does not cancel the provider call or imply zero charge.

Python

Install requests. Use a new idempotency key for a new logical request; retain it for retries of that same request.

Python
import os, uuid, requests
response = requests.post(
    "https://platform-backend.topview.ai/v1/messages",
    headers={"Authorization": "Bearer " + os.environ["TOPVIEW_API_KEY"],
             "Idempotency-Key": uuid.uuid4().hex},
    json={"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"Hello"}],"max_tokens":1024},
    timeout=180,
)
print("Request ID:", response.headers.get("X-Platform-Request-Id"))
response.raise_for_status()
print(response.json())

JavaScript

Run on your server. Inspect non-2xx responses before parsing generated output.

JavaScript
const response = await fetch("https://platform-backend.topview.ai/v1/messages", {
  method: "POST",
  headers: {Authorization: "Bearer " + process.env.TOPVIEW_API_KEY,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID()},
  body: JSON.stringify({
  "model": "claude-sonnet-4-6",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 1024
}),
});
const data = await response.json();
if (!response.ok) throw new Error(JSON.stringify(data));
console.log(response.headers.get("X-Platform-Request-Id"), data);

Attachments and URLs

Messages accepts PNG/JPEG/WebP/non-animated GIF image blocks and PDF document blocks with Base64 or public HTTPS URL sources. Plain-text document sources and content-block document sources are supported. Use source.type=text with media_type=text/plain for extracted text. Native Word/Excel files are not accepted by this Messages route; convert them to PDF or extract their text. Playground reads text files and CSV as text.

Attachments and URLs
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "document",
          "source": {
            "type": "url",
            "url": "https://example.com/document.pdf"
          }
        },
        {
          "type": "image",
          "source": {
            "type": "url",
            "url": "https://example.com/image.png"
          }
        },
        {
          "type": "text",
          "text": "Summarize the document and image."
        }
      ]
    }
  ]
}

Attachment delivery and limits

Platform limit: 20 MiB combined decoded attachments, including generated GPT PDF page images, and 32 MiB request JSON. Up to 600 images / PDF pages, subject to each model context and upstream limits. URLs must be publicly readable HTTPS direct file links without credentials or redirects; private networks are rejected. URLs are fetched and frozen before reservation. Base64 image sources use the matching media type; PDF uses application/pdf. GPT file_data accepts a data URL (or raw Base64 with a .pdf filename). Provider file_id/Files APIs are not exposed by this supplier. A web page URL in plain text is only text; hosted web-fetch/search tools are not enabled. Image and PDF page tokens contribute to input usage; an attachment reservation is conservative and unused funds are released. The API response retains PDF citations when requested through the native protocol.

Pricing and billing

Prices are USD per million tokens: input 2.55; output 12.75; cache read 0.255. Cache write (5 minutes): 3.1875; cache write (1 hour): 5.1. The wallet reserves a conservative budget before submission, charges actual reported token usage and releases the unused reservation. The reservation is not the final charge. Check Usage for settlement and the request ID. Image/video promotions should not be assumed to apply to text.

Errors, retries and idempotency

Save X-Platform-Request-Id. Supply Idempotency-Key (16–128 letters, digits, underscore or hyphen). Reuse the same key and identical payload with the same API credential when recovering the same request. A settled replay does not call the provider again; an active or uncertain request returns 409. A new key creates a new paid request. Invalid input returns 400; authentication or access errors use 401/403. Do not blindly resubmit after a timeout, 5xx or interrupted stream: provider execution may have occurred. Check Usage and the original request ID; uncertain usage requires reconciliation. A confirmed provider rejection releases the reservation.

Find model docs