API Reference
Chat API
Chat with premium LLMs proxying requests via OpenRouter with credit billing.
The chat API allows you to generate conversational completions or execute complex instruction-following prompts using top-tier LLMs through one unified, white-labeled interface (serpermatrix/chat).
Requests are proxied with high availability and token-level billing accuracy, automatically deducting credits from your SerperMatrix account balance.
Message Object Structure
The messages array maintains the full conversational context. Each object inside messages requires a role and content:
| Role | Description | Example Usage |
|---|---|---|
system | Sets background context, persona, or output constraints | "You are a concise research assistant." |
user | User input instructions, search queries, or document text | "Summarize the key features of Nuxt 3." |
assistant | Previous assistant responses for multi-turn conversations | "Nuxt 3 features auto-imports and SSR." |
{
"messages": [
{ "role": "system", "content": "You are a helpful coding assistant." },
{ "role": "user", "content": "Why is SerperMatrix so fast?" }
],
"temperature": 0.7,
"max_tokens": 4096
}
Sampling & Generation Parameters
temperature: Controls randomness.0.0produces deterministic code/data extraction;0.7–1.0is recommended for creative writing and chatting.max_tokens: Maximum number of tokens allowed in the generated output (up to 16,384 tokens).
Usage & Credit Tracking Envelope
Every successful chat completion response returns detailed token accounting in the usage object:
prompt_tokens: Number of tokens in your input prompt and conversation historycompletion_tokens: Number of tokens generated in the assistant's responsetotal_tokens: Total sum of prompt and completion tokenscredits_used: Exact credit cost deducted for the requestcredits_remaining: Your remaining SerperMatrix account credit balance
Authorizations
X-API-KEYstringheaderrequired
Passed via request headers. Your secret API key for SerperMatrix (e.g.
sm_live_...).Body
application/json
messagesarrayrequired
A list of message objects, representing the chat conversation context. Minimum
1, maximum 100 messages.temperaturefloatdefault: 0.7
Sampling temperature between
0.0 and 2.0. Lower values are more deterministic; higher values are more creative.max_tokensintegerdefault: 4096
The maximum tokens allowed in the completion (min:
1, max limit: 16,384 tokens).Message Objects
The structured format of each element inside the messages array:
rolestringrequired
Role of the message author. Allowed values:
"user", "assistant", "system".contentstringrequired
Text content of the message payload (max length:
50,000 characters). Request
curl -X POST https://serpermatrix.com/api/v1/chat/ \
-H "X-API-KEY: sm_live_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Why is SerperMatrix so fast?"}],"temperature":0.7,"max_tokens":4096}'{
"id": "gen-kp92p6s...",
"object": "chat.completion",
"model": "serpermatrix/chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "SerperMatrix is highly optimized because it integrates direct caching, high-speed regional network tunnels, and concurrent proxy routing."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 36,
"total_tokens": 50,
"credits_used": 15,
"credits_remaining": 98450
}
}