Skip to navigation

Chat Completions

POST /waves/v1/chat/completions - OpenAI-compatible chat completion API. Full request and response reference.

View as Markdown

POST https://api.smallest.ai/waves/v1/chat/completions

OpenAI-compatible chat completion endpoint. Most OpenAI Chat Completions request fields are accepted and passed through to Electron verbatim. The response shape matches OpenAI’s chat.completion object.

Request

Authentication

Authorization: Bearer $SMALLEST_API_KEY

Required fields

FieldTypeDescription
modelstringAlways "electron".
messagesarrayStandard OpenAI message array. Max 200 messages. Each message: {role, content, tool_calls?, tool_call_id?} where role is "system", "user", "assistant", or "tool".

Common optional fields

FieldTypeDefaultNotes
temperaturenumber ≥ 01.0Sampling temperature.
top_pnumber 0–11.0Nucleus sampling.
max_tokensintmodel maxCap on output tokens for this completion. The 32,768-token model ceiling is on combined input + output, so max_tokens is effectively 32,768 − prompt_tokens.
streamboolfalseWhen true, response is Server-Sent Events. See Streaming.
stream_options.include_usageboolfalseWhen true (with stream: true), final SSE chunk carries the usage block.
stream_options.continuous_usage_statsboolfalseWhen true (with stream: true and include_usage: true), every SSE chunk carries a usage block with the token counts so far. No effect without include_usage.
stopstring | array of strings-Up to 4 stop sequences.
seedintrandomBest-effort determinism.
response_formatobject-{"type":"text"} (default) or {"type":"json_object"}.
toolsarray-Standard OpenAI function-calling tools array. Max 64 entries. See Tool Calling.
tool_choicestring | object"auto""auto", "required", "none", or {"type":"function","function":{"name":"…"}}.
logit_biasobject-Per-token id biases.
logprobsboolfalseReturn log-probabilities.
top_logprobsint 0–20-Top-N log-probs (requires logprobs: true).
presence_penalty, frequency_penaltynumber −2 to 20Standard OpenAI knobs.

Unrecognized parameters not in the supported set are accepted by the schema but may be ignored by the model. See Supported Parameters for the full passthrough table.

Explicitly rejected fields

FieldWhy
n > 1Cost amplification with no use case in v1.
prompt_logprobsResponse-size amplification with no billing impact.

Sending either returns HTTP 400 with invalid_request_error.

Response

Non-streaming (default)

Standard OpenAI chat.completion object:

{
"id": "chatcmpl-a670053f3ab2ed8f",
"object": "chat.completion",
"created": 1740000000,
"model": "electron",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi! How can I help you today?",
"tool_calls": null
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 9,
"total_tokens": 29,
"prompt_tokens_details": {
"cached_tokens": 0
}
}
}

usage block

FieldDescription
prompt_tokensTotal input tokens (cached + uncached).
prompt_tokens_details.cached_tokensSubset of prompt_tokens served from prefix cache. Billed at the discounted rate. See Prefix Caching.
completion_tokensGenerated output tokens.
total_tokensprompt_tokens + completion_tokens.

finish_reason

ValueMeaning
"stop"Natural stop (end token or stop sequence hit).
"length"max_tokens reached.
"tool_calls"The model returned function calls; act on them and continue the conversation.
"content_filter"Content blocked.

Streaming

When stream: true, the response is text/event-stream SSE. See Streaming for chunk format and example consumer code.

Errors

Errors use the OpenAI-style envelope. Validation failures also include a details array with per-field reasons:

{
"error": {
"message": "Invalid input data",
"type": "invalid_request_error",
"param": null,
"code": null,
"details": [
{ "code": "custom", "message": "n > 1 is not supported", "path": ["n"] }
],
"request_id": "9db74058-2421-4793-8796-b2629ff3eb1c"
}
}
FieldDescription
error.messageHuman-readable summary.
error.typeWhat went wrong. See the table below.
error.paramThe request field at fault, such as model, when there is one. Otherwise null.
error.coderate_limit_exceeded on rate-limit errors, insufficient_quota when credits run out. Otherwise null.
error.detailsPresent on schema-validation failures. Array of {code, message, path} entries naming the offending fields. Use the path array to highlight the bad field in your client.
error.request_idUnique trace ID. Always include it in support tickets. Also returned as the X-Request-Id response header.
Statuserror.typeWhen
400invalid_request_errorValidation failed, the model isn’t available, or the context length was exceeded.
400insufficient_quotaYour credits are used up. Recharge to continue.
401-Missing or invalid API key. See the note below.
403permission_errorYour plan doesn’t include Electron, or your organization’s billing is blocked.
429requestsYou hit your requests-per-minute limit.
429concurrencyToo many requests in flight at once.
500server_errorUnexpected server error. Retry with backoff.
502upstream_errorThe model is unavailable. Retry with backoff.
503upstream_overloadedThe model is overloaded. Retry with backoff.
503service_unavailableElectron is temporarily unavailable. Retry after Retry-After seconds when the header is present.

Authentication is checked before the request reaches Electron, so a missing or invalid API key returns 401 with a short body such as {"error": "unauthorized"}, not the envelope above. An access token (wat_…) isn’t accepted on this endpoint and returns 403 with {"error": "forbidden"}; use an API key. For these, check the status code, not the body.

Response headers

HeaderWhen
X-Request-IdOn every response. Same value as error.request_id.
Retry-AfterOn 429 and some 503 responses. Seconds to wait before retrying. A 429 without it means your plan doesn’t include this API, so retrying won’t help.
x-ratelimit-limit-requests, x-ratelimit-remaining-requests, x-ratelimit-reset-requestsWhen your plan has a requests-per-minute limit. reset is the time until the limit is fully free again, such as 12s.

Examples

Minimal

import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.smallest.ai/waves/v1",
api_key=os.environ["SMALLEST_API_KEY"],
)
resp = client.chat.completions.create(
model="electron",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain prefix caching in one sentence."},
],
)
print(resp.choices[0].message.content)

Multi-turn

messages = [
{"role": "system", "content": "You are a customer-support agent."},
{"role": "user", "content": "I want to change my plan."},
{"role": "assistant", "content": "Sure — which plan are you on right now?"},
{"role": "user", "content": "Standard, and I want to upgrade to Enterprise."},
]
resp = client.chat.completions.create(model="electron", messages=messages)

JSON object output

resp = client.chat.completions.create(
model="electron",
messages=[
{"role": "system", "content": "Reply with strict JSON."},
{"role": "user", "content": "List three Indian state capitals as {\"capitals\": [...]}"},
],
response_format={"type": "json_object"},
temperature=0,
)