NEWTry the playground — no API key required
Skip to content
Documentationv1

API documentation

Reference for the unified API: authentication, endpoints, routing, streaming and error handling.

Getting started

Introduction

The API gives you one endpoint and one request format for every model in the catalog. Requests are OpenAI-compatible, so most existing clients work by changing the base URL and API key.

Base URL
https://api.pivotra.tech/v1

Responses include a routing object describing which model served the request and a usage.cost field with the exact cost in USD.

Getting started

Authentication

Authenticate every request with a secret key in the Authorization header. Create and revoke keys in the dashboard under API Keys. A key is shown only once at creation — store it in a secret manager.

Header
Authorization: Bearer pv-live-••••••••••••••••

Never expose secret keys in client-side code. Proxy requests through your backend instead.

API reference

Chat completions

POST /v1/chat/completions — generate a response for a conversation.

ParameterTypeRequiredDescription
modelstringYesA model ID from the catalog, or "auto" to use routing.
messagesarrayYesConversation turns with role and content.
temperaturenumberNoSampling temperature, 0–2. Default 1.
max_tokensintegerNoUpper bound on generated tokens.
streambooleanNoStream tokens as server-sent events.
routingobjectNoPer-request routing policy. See Routing.
1import Pivotra from "@pivotra/sdk";2 3const client = new Pivotra({ apiKey: process.env.API_KEY });4 5const response = await client.chat.completions.create({6  model: "gpt-6-luna",7  messages: [8    { role: "user", content: "Summarize this support ticket in one sentence." },9  ],10});11 12console.log(response.choices[0].message.content);13console.log(response.routing.model, response.usage.cost);
200 response
1{2  "id": "req_8f2a91c04b7d",3  "object": "chat.completion",4  "model": "gpt-6-luna",5  "routing": {6    "strategy": "balanced",7    "model": "gpt-6-luna",8    "provider": "openai",9    "fallback_used": false,10    "decision_ms": 311  },12  "choices": [13    {14      "index": 0,15      "message": { "role": "assistant", "content": "Customer cannot reset their password after the latest update." },16      "finish_reason": "stop"17    }18  ],19  "usage": { "prompt_tokens": 182, "completion_tokens": 14, "total_tokens": 196, "cost": 0.0000357 }20}
API reference

Routing object

Set model: "auto" to let the engine choose. Optional fields override your workspace default policy for a single request.

ParameterTypeRequiredDescription
strategyenumNobalanced | cost | latency | quality
preferredstringNoModel to try first when eligible.
fallbacksstring[]NoOrdered alternates on failure or ineligibility.
constraints.max_latency_msintegerNoExclude models above this TTFT.
constraints.requirestring[]NoRequired capabilities, e.g. tools, vision, json.
API reference

Streaming

Set stream: true to receive server-sent events. Each chunk contains a delta; the final event includes usage and routing metadata.

stream.ts
1const stream = await client.chat.completions.create({2  model: "auto",3  stream: true,4  messages: [{ role: "user", content: "Write a haiku about latency." }],5});6 7for await (const chunk of stream) {8  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");9}
API reference

List models

GET /v1/models returns the catalog with pricing, context window, capabilities and availability for each model.

request.sh
1curl https://api.pivotra.tech/v1/models \2  -H "Authorization: Bearer $API_KEY"
Guides

Errors & retries

Errors return a JSON body with code, message and request_id. Include the request ID when contacting support.

ParameterTypeRequiredDescription
400invalid_request—Malformed body or unsupported parameter.
401unauthorized—Missing, invalid or revoked API key.
402insufficient_credit—Balance exhausted or spending limit reached.
402spend_limit_reached / key_limit_reached—Workspace or key monthly limit reached.
429rate_limit_exceeded—Too many requests for this key. Honour Retry-After.
500/503upstream_error—Provider failure. Fallbacks run automatically when configured.
errors.ts
1import Pivotra, { APIError, RateLimitError } from "@pivotra/sdk";2 3try {4  const res = await client.chat.completions.create({ model: "auto", messages });5} catch (err) {6  if (err instanceof RateLimitError) {7    // 429 — respect the Retry-After header8    await sleep(err.retryAfterMs);9  } else if (err instanceof APIError) {10    console.error(err.status, err.code, err.requestId);11  } else {12    throw err;13  }14}
Guides

Rate limits

Each API key may send 60 requests per minute by default, counted in fixed one-minute windows. The limit is shown next to each key in the dashboard and can be raised to 1,000 per minute per key.

Every response carries x-ratelimit-limit, x-ratelimit-remaining and x-ratelimit-reset (Unix seconds). Over the limit you get 429 rate_limit_exceeded with a Retry-After header. Spending limits are separate and return 402.

Guides

Integration guides

Because the API follows the OpenAI chat completions schema, you can migrate an existing integration by changing two values:

openai-compatible.ts
1import OpenAI from "openai";2 3const client = new OpenAI({4  baseURL: "https://api.pivotra.tech/v1",5  apiKey: process.env.API_KEY,6});