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":"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="gpt-6-astra",
messages=[{"role": "user", "content": "Reply with a short greeting."}],
)
print(response.choices[0].message.content)Troubleshooting
- Authentication fails
- Check that the saved TokenRex key is active and belongs in the tool's API-key field, not its subscription sign-in. Remove accidental spaces, check your wallet balance, and never share the key in screenshots or exported settings.
- The model is missing or the request URL returns 404
- Copy an exact enabled model ID from Models & Pricing. Follow this method's URL field: some tools expect the versioned base, others the root or full completion address. Check the documented API protocol before changing the path.
- Chat works but streaming or tools fail
- Test a short plain-text conversation first. Confirm the selected model and installed tool version support the required protocol and capabilities. Enable agent actions only after separately checking streaming and tool calls.
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.