Stable AI API docs

Fastest integration: change the base URL and use a Trex key.

TrexAPI provides an OpenAI-compatible API, model routing, multi-provider fallback, API key management, basic logs, and subscription-state controls. The goal is to give your app a stable AI fallback interface.

https://api.trexapi.com/v1POST /v1/chat/completionsPOST /v1/responsesGET /v1/models

How Stable AI API works

Complexity moves into the platform layer: authentication, rate limits, quota, routing, fallback, billing, and risk controls are handled by Trex.

Stability first

TrexAPI performs authentication, rate, quota, and account-state checks before routing. The platform protects stability instead of allowing unbounded traffic by default.

One endpoint, multiple fallback providers

Clients call one OpenAI-compatible endpoint while provider choice, model catalog, and fallback plans stay in the Trex control plane.

Quota and balance tiers

Smart Auto uses daily quota. Premium, pinned providers, long context, and high concurrency use Compute Credits.

Quickstart

Works with the OpenAI SDK, compatible clients, and direct HTTP calls.

1

Create a Trex API key.

2

Set the OpenAI-compatible client `baseURL` to `https://api.trexapi.com/v1`.

3

Replace `apiKey` with the Trex key.

4

Bind provider keys in the dashboard, or use the managed route configured for your account.

Node

import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.TREX_API_KEY, baseURL: "https://api.trexapi.com/v1", }); const response = await client.chat.completions.create({ model: "smart-auto", messages: [ { role: "user", content: "Summarize today's incident handoff." } ], }); console.log(response.choices[0].message.content);

Python

from openai import OpenAI import os client = OpenAI( api_key=os.environ["TREX_API_KEY"], base_url="https://api.trexapi.com/v1", ) response = client.chat.completions.create( model="smart-auto", messages=[ {"role": "user", "content": "Summarize today's incident handoff."} ], ) print(response.choices[0].message.content)

Model catalog and fallback

`GET /v1/models` returns the model catalog available to the current Trex key. Non-streaming requests can declare fallbacks; Trex retries fallback paths on retryable failures such as network errors, 429, 502, 503, and 504.

curl https://api.trexapi.com/v1/models \ -H "Authorization: Bearer $TREX_API_KEY"

Explicit fallback example

const response = await fetch("https://api.trexapi.com/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${process.env.TREX_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4o-mini", messages: [{ role: "user", content: "Write a short status update." }], trex: { routing: { fallbacks: [ { provider: "openrouter", model: "openai/gpt-4o-mini" } ] } } }), }); console.log(response.headers.get("X-Trex-Upstream-Provider"));

API keys and provider binding

  • `Authorization` uses `Bearer <trex_api_key>`.
  • Provider keys are stored in the dashboard and bound to Trex keys by default.
  • For temporary overrides, requests may send `X-Upstream-Api-Key`.
  • Inactive, revoked, or suspended API keys return `401`.

Limits and errors

  • Explicit fallback currently applies to non-streaming calls to avoid duplicate billing after an upstream has started producing output.
  • Rate-limited requests return a structured `429` with `Retry-After`.
  • Quota exhaustion, insufficient balance, missing provider bindings, and inactive API keys return structured JSON errors.
  • Third-party provider account state, outputs, policies, and availability remain governed by that provider.

Create one key and verify the stable path.

Use the dashboard to manage API keys, provider bindings, subscriptions, quota, and basic logs.