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
TokenRex

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.

typescript
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 URLPurpose
POST /chat/completionsChat, streaming, supported vision and function tools
POST /responsesResponses-style reasoning and supported tools
POST /messagesNative Messages, streaming, supported remote MCP and caching
POST /images/generations · /images/editsImage generation and editing
POST /audio/speech · /audio/transcriptionsSpeech output and recorded-audio transcription
POST /musicMusic generation
POST /embeddingsNumeric vectors
POST /decisionsTyped classification, scores and routing
POST /videosStart a video job
GET /videos/{id} · /videos/{id}/contentPoll status and download a completed video
WSS /liveAuthorized live audio sessions
GET /modelsPublic 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.