API integration and SDKs
Understand the protected app connection, server-side API calls, compatible SDKs and endpoint formats.
By Apirex Team · Updated · Sources checked
On this page

Two integration paths
Inside an Apirex-hosted web app, use the protected project connection created when you choose TokenRex AI. Apirex keeps the app-specific credential private. A separate backend is not needed merely to hold that key. Native and externally hosted apps need a protected server integration; installing a private key inside a mobile app is not secure.
Direct TokenRex API
For an independently configured server integration, TokenRex’s base URL is https://tokenrex.ai/api/public/v1. Authenticate server-side with Authorization: Bearer and a valid private key. Compatible OpenAI-style SDKs accept a custom base URL for Chat Completions. Native Messages and Responses have different schemas; compatibility does not mean every SDK method or setting works on every model.
import OpenAI from "openai";
// Server-side only. Store the key in a secret, never browser source.
const client = new OpenAI({
baseURL: "https://tokenrex.ai/api/public/v1",
apiKey: process.env["TOKENREX_API_KEY"],
});
const result = await client.chat.completions.create({
model: "gpt-6-luna",
messages: [{ role: "user", content: "Summarize this short paragraph…" }],
});Endpoint reference
| Path under the base URL | Purpose |
|---|---|
| POST /chat/completions | Chat, streaming, supported vision and function tools |
| POST /responses | Responses-style reasoning and supported tools |
| POST /messages | Native Messages, streaming, supported remote MCP and caching |
| POST /images/generations · /images/edits | Image generation and editing |
| POST /audio/speech · /audio/transcriptions | Speech output and recorded-audio transcription |
| POST /music | Music generation |
| POST /embeddings | Numeric vectors |
| POST /decisions | Typed classification, scores and routing |
| POST /videos | Start a video job |
| GET /videos/{id} · /videos/{id}/content | Poll status and download a completed video |
| WSS /live | Authorized live audio sessions |
| GET /models | Public model catalog and current prices |
Preview and local development
Use the project’s secure preview address for the complete hosted connection. On the paired computer, the current helper can forward local-preview AI calls to that protected project connection. A bare local server that bypasses it may show the website but fail on AI requests. Never repair that by copying a hidden key into the app’s source.
Test the actual feature
- Read the exact endpoint and model settings before coding.
- Try a real input through the running app, not just a mocked reply.
- Check AI activity for the model, request status, response and recorded charge.
- Test missing permissions, unavailable service and exhausted eligible balance.
- Publish and repeat the feature on its live address.