OpenAI & Anthropic Compatible API
Strata includes an embedded high-concurrency web server listening on http://localhost:8080. It functions as a drop-in replacement for OpenAI and Anthropic cloud APIs.
http://localhost:8080/v1 Supports /chat/completions, /completions, and /models http://localhost:8080/anthropic/v1 Supports /messages format with streaming 1. Python Client (OpenAI SDK)
pip install openaifrom openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/v1",
api_key="strata-local-token" # Any string works locally
)
response = client.chat.completions.create(
model="qwen3.8-125b-q4",
messages=[
{"role": "system", "content": "You are a senior system architect."},
{"role": "user", "content": "Explain how sparse MoE routing works in 3 bullet points."}
],
temperature=0.7,
stream=True
)
for chunk in response:
content = chunk.choices[0].delta.content or ""
print(content, end="", flush=True) 2. TypeScript / Node.js
npm install openaiimport OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'http://localhost:8080/v1',
apiKey: 'strata-local',
});
async function main() {
const stream = await openai.chat.completions.create({
model: 'qwen3.8-125b-q4',
messages: [{ role: 'user', content: 'Write a quicksort in Rust.' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
}
main(); 3. Continue.dev (VS Code / JetBrains) Config
Add the following block into your ~/.continue/config.json to use Strata as your free offline local coding assistant:
{
"models": [
{
"title": "Strata Qwen 125B (Local)",
"provider": "openai",
"model": "qwen3.8-125b-q4",
"apiBase": "http://localhost:8080/v1",
"apiKey": "local"
}
]
} 4. Chat Completions Endpoint Parameter Reference
When sending requests to POST /v1/chat/completions or POST /anthropic/v1/messages, you can control sampling determinism, output budgets, and streaming behavior using standard JSON body parameters. Understanding how these parameters interact with local KV cache allocation helps prevent unexpected latency spikes on 12GB–24GB GPUs.
| Parameter | Type | Default | Behavior & Local Tuning Notes |
|---|---|---|---|
| model | string | Required | Identifier of the loaded checkpoint (e.g., qwen3.8-125b-q4). Query GET /v1/models to list active local IDs. |
| messages | array | Required | Ordered list of system, user, and assistant turns. Keep total token count below your server's --ctx-size. |
| temperature | number | 0.7 | Controls sampling randomness (0.0–2.0). Use 0 or 0.1 for code generation, JSON extraction, and reproducible benchmarks. |
| top_p | number | 0.95 | Nucleus sampling cutoff. Avoid adjusting both temperature and top_p aggressively at the same time. |
| max_tokens | integer | Auto | Hard cap on generated completion tokens. Setting an explicit cap (e.g., 1024 or 2048) prevents runaway loops during automated batch jobs. |
| stream | boolean | false | Enables Server-Sent Events (SSE) token streaming. Always enable in interactive chat and IDE extensions to reduce perceived latency. |
| stop | string[] | null | Up to 4 custom stop sequences that immediately halt generation—useful for fill-in-the-middle (FIM) code completion. |
| seed | integer | random | Fixed RNG seed for repeatable outputs when paired with temperature: 0. |
5. Common HTTP & Runtime Error Codes
When integrating local inference into scripts or IDE agents, network timeouts and context-window overflows behave differently than cloud APIs. Use the diagnostic table below to handle local server status codes cleanly.
| Status Code | Typical Cause | Recommended Remediation |
|---|---|---|
| 400 Bad Request | Prompt tokens exceed configured --ctx-size or malformed JSON role sequence. | Truncate conversation history, summarize older turns, or restart the server with a larger context window and --kv-cache-type q8_0. |
| 404 Not Found | Missing /v1 prefix in client base_url or mismatched model name string. | Verify GET http://localhost:8080/v1/models and copy the exact id field into your client config. |
| 422 Unprocessable | Unsupported parameter type (such as passing a string for max_tokens or invalid tool schema). | Validate your request payload against the OpenAI Chat Completions JSON schema before posting. |
| 500 Internal Error | CUDA Out-of-Memory (OOM) during prompt prefill or pinned host RAM exhaustion. | Check server console logs, lower --vram-budget by 1–2 GB, or review our Context Load OOM Playbook. |
| 503 Service Busy | Model checkpoint is still loading weights into pinned RAM/VRAM or another long request holds the slot. | Implement exponential backoff (2s → 5s → 10s) in client scripts during cold startup. |
6. Production cURL (Streaming SSE) & Anthropic SDK Examples
For shell automation, health checks, or CI smoke tests, use curl -N (disable output buffering) to observe real-time token streaming and measure time-to-first-token (TTFT) directly from the terminal. Always raise client read timeouts to at least 120 seconds when sending 8K–16K token code prompts so long prefills do not abort mid-flight.
# Streaming SSE test via cURL (OpenAI-compatible endpoint)
curl -N http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer strata-local" \
-d '{
"model": "qwen3.8-125b-q4",
"temperature": 0,
"max_tokens": 256,
"stream": true,
"messages": [
{"role": "system", "content": "Be concise and technical."},
{"role": "user", "content": "Compare PCIe 4.0 x16 and PCIe 5.0 x16 for MoE offloading."}
]
}'
If your application or agent harness uses the official Anthropic Python SDK (pip install anthropic), point base_url to http://localhost:8080/anthropic with a generous timeout:
import anthropic
client = anthropic.Anthropic(
base_url="http://localhost:8080/anthropic",
api_key="strata-local-key",
timeout=180.0,
)
with client.messages.stream(
model="qwen3.8-125b-q4",
max_tokens=512,
temperature=0.1,
messages=[{"role": "user", "content": "Audit this Dockerfile for layer caching issues."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True) Related: Full IDE Coding Stack Guide · Benchmark Methodology →