Use TokenRex with API Integration
Connect your own application using HTTP or the OpenAI Python SDK.
These examples use TokenRex's documented Chat Completions endpoint. SDK and app-specific tool behavior should be tested separately.
Before you start
- A TokenRex API key
- An enabled model ID
- A private server or local development environment
Setup methods
Direct HTTP request
- 1.
Create a TokenRex API key and store it privately in TOKENREX_API_KEY.
- 2.
Copy an enabled model ID from Models & Pricing and use the Chat Completions request below.
- 3.
Read choices[0].message.content and confirm the selected model in your usage. Do not put a private key in browser code or a public repository.
curl https://tokenrex.ai/api/public/v1/chat/completions \
-H "Authorization: Bearer $TOKENREX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-6-astra","messages":[{"role":"user","content":"Reply with a short greeting."}]}'OpenAI Python SDK
- 1.
Install openai in your Python environment and set TOKENREX_API_KEY privately.
- 2.
Set base_url to the versioned TokenRex URL, then call chat.completions.create with an enabled model ID.
- 3.
Keep requests on your server or local environment; do not expose the key to visitors.
import os
from openai import OpenAI
client = OpenAI(base_url="https://tokenrex.ai/api/public/v1", api_key=os.environ["TOKENREX_API_KEY"])
response = client.chat.completions.create(
model="openai/gpt-6-astra",
messages=[{"role": "user", "content": "Reply with a short greeting."}],
)
print(response.choices[0].message.content)Verify the connection
Send a short message with the selected model, read its response, then confirm the exact model appears in your TokenRex usage. Test streaming and tool use separately before larger agent tasks.