Skip to main content
@formthefog/stratus-sdk-ts is the native TypeScript client for Stratus X1 — it exposes every endpoint, handles retries with exponential backoff, and ships compression utilities and vector DB adapters alongside the core API surface.

Installation

Import the client:

Quick Start

A minimal working example from zero to first response:
STRATUS_API_KEY is the only required credential. Formation’s shared pool handles LLM calls automatically on day one — no provider key needed to get started. Add your own key at any time to remove the 25% pool markup. See Authentication for the full key resolution flow.

Constructor options


Chat Completions

client.chat.completions.create(request)

Posts to POST /v1/chat/completions and returns a Promise<ChatCompletionResponse>. Retries up to config.retries (default 3) on transient failures with exponential backoff — 1s, 2s, 4s. Non-retried on 400, 401, and 422.

Hybrid orchestration extensions

The stratus field on the request activates advanced planning modes:
The stratus.mode field controls how the X1 world model engages. hybrid combines planning and validation in a single pass — it plans a full action sequence, verifies the predicted outcome against your threshold, and re-plans automatically if confidence falls short.

Inline LLM keys

Pass provider keys per-request rather than storing them in vault. Useful for CI, multi-tenant setups, or quick testing:
Supported fields: openai_key, anthropic_key, gemini_key, openrouter_key.

client.chat.completions.stream(request)

Forces stream: true and returns AsyncGenerator<ChatCompletionChunk>. Planning metadata appears on the first chunk’s stratus field.
brain_signal surfaces the X1 brain’s internal read on the current state — it tells you which action type the planner committed to, whether a simulation confirmed that choice, and how far the predicted outcome sits from the goal. Use brain_signal.goal_proximity as a normalized progress indicator across a multi-step task.

Messages (Anthropic Format)

client.messages(request) posts to POST /v1/messages — the Anthropic-native endpoint. Use this if your codebase already speaks the Anthropic SDK format. The request takes an AnthropicRequest and the response is a standard AnthropicResponse extended with stratus?: StratusMetadata.
max_tokens is required in the Anthropic format — unlike the OpenAI endpoint where it is optional. The system parameter is the natural place to describe environment state for Stratus world model planning.
Alternatively, point the official Anthropic SDK at Stratus directly — no StratusClient required:

Embeddings

client.embeddings(request) posts to POST /v1/embeddings. For embeddings, use the model name without an LLM suffix — stratus-x1ac-base (not stratus-x1ac-base-gpt-4o). The encoder produces 768-dimensional vectors for the base model.
Batch multiple texts in a single call:
Use encoding_format: 'base64' for high-throughput pipelines — the payload is ~25% smaller and decodes cleanly with Buffer.from(str, 'base64').
Stratus embeddings are optimized for agent state and action semantics — not general-purpose text. They excel at state similarity, goal matching, and pattern retrieval from agent memory. For document search or FAQ matching, general-purpose embeddings (OpenAI text-embedding-3, Cohere embed-v3) are a better fit.

Rollout

client.rollout(request) posts to POST /v1/rollout — pre-execution simulation. Give it a goal and an initial state description; it plans a full action sequence through the world model and returns predicted outcomes at each step before anything executes.
Use rollout as a pre-flight check before committing real actions:
The summary.planner field tells you which path the X1 brain took: brain means the top-level policy head selected actions directly; action_planner means a forward search was run through the world model to find the best sequence. Either path produces valid plans — the distinction is useful for debugging and cost tracking since forward search is more compute-intensive.

Models

client.listModels() calls GET /v1/models. No authentication required. Returns the full list of available stratus-x1ac-{size}-{llm} combinations — every planning model size paired with every supported downstream LLM.
Start with stratus-x1ac-base-gpt-4o — it’s the production-tested default. Reach for small when latency is the constraint, large when accuracy on complex multi-step tasks isn’t sufficient with base. Do not default to large as a safety measure.

LLM Key Management

Store your provider keys once in Stratus vault — encrypted at rest with AES-256-GCM — and every future request uses them automatically, bypassing the Formation pool markup entirely.

client.account.llmKeys.set(keys)

Posts to POST /v1/account/llm-keys. All fields optional — provide any combination. Omitted keys remain unchanged.
Stratus validates each key against its provider before storing. If validation fails, the request returns a 400 with the provider name and rejection reason.

client.account.llmKeys.get()

Calls GET /v1/account/llm-keys. Returns presence and last-validated timestamps — never the raw key values.
formation_keys_available is true for all active accounts. Even after you store your own keys, Formation’s pool remains available as a fallback — it activates only when no native key is found for a given provider. You can remove it as the path for a specific provider by storing that provider’s key.

client.account.llmKeys.delete(provider?)

Calls DELETE /v1/account/llm-keys. Pass a provider name to remove a single key, or omit to delete all stored keys.
Accepted values: 'openai', 'anthropic', 'google', 'openrouter'.

Credits

client.credits.packages()

Calls GET /v1/credits/packages. No authentication required. Lists available credit packages with current pricing.

client.credits.purchase(pkg, paymentHeader)

Posts to POST /v1/credits/purchase/{pkg} with an X-PAYMENT header containing a signed x402 transaction. On success, returns a CreditPurchaseResponse — and for first-ever account creation, the response includes stratus_api_key with your new key.
See Credits & Billing for the full x402 payment flow and card purchase instructions.

Error Handling

The SDK throws StratusAPIError for any non-2xx response. Catch it and branch on errorType:

StratusAPIError shape

Retry behavior

The client retries automatically on any error that is not 400, 401, or 422. Backoff is exponential starting at 1s: 1s → 2s → 4s. The number of retries is controlled by config.retries (default 3). To disable retries entirely, set retries: 0 in the constructor.
authentication_error (401) and validation errors (400, 422) are never retried — retrying them without fixing the underlying problem burns your retry budget without any chance of success. Fix the request before re-sending.

Compression Utilities

@formthefog/stratus-sdk-ts ships a suite of vector compression and quality analysis utilities alongside the API client. Use them to reduce embedding storage costs by 10–20× with 99%+ retention quality.

Compression profiles

Pre-tuned profiles for common embedding shapes:
Use MJEPA_768_* profiles for vectors produced by stratus-x1ac-base. Use OPENAI_* profiles for OpenAI text-embedding-3 vectors.

Vector DB adapters

Drop-in adapters for Pinecone, Weaviate, and Qdrant that compress vectors before upsert and decompress on fetch — transparently:

Health Check

client.health() calls GET /health. No authentication required. Returns current system status — use it to check whether vault is available before calling account.llmKeys.set().
LLM key vault storage (account.llmKeys.set) requires health.vault === 'connected'. If vault is disabled, stored-key calls fall back to the Formation pool automatically — but new keys cannot be persisted until the vault reconnects.

Next Steps

Authentication

Set up your Stratus API key, configure BYOK, and understand the three-tier key resolution flow.

API Reference

Full endpoint docs, request parameters, response shapes, and error codes.

Tutorials

Real-world agents — web navigation, cascade prediction, and concurrent task orchestration.