Use the AI Router with the OpenAI SDK · Galaxium Hosting help
Point curl or any OpenAI-compatible SDK at the AI Router base URL with a gx- key to use models from many providers.
The AI Router is OpenAI-compatible. Any OpenAI SDK or tool that lets you set a base URL works with it, and one key gives you access to models from several providers.
Before you start
- Base URL: your portal address followed by
/v1. Copy it from the Quick start card on the AI Router overview. - API key: create one under AI Router → API keys. Keys start with
gx-and are shown only once. - Credits: requests are paid from your AI credit balance. See AI credits and auto top-up.
- Model ID: copy it from Models, for example
openai/gpt-4o-minioranthropic/claude-sonnet-4.6. If you leave the model out, your Default model from Settings is used.
The Quick start card has these same examples with your base URL already filled in.
curl
Store your key in an environment variable first (export GALAXIUM_API_KEY=gx-...), then:
curl https://YOUR-PORTAL-ADDRESS/v1/chat/completions \
-H "Authorization: Bearer $GALAXIUM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Python
from openai import OpenAI
client = OpenAI(
base_url="https://YOUR-PORTAL-ADDRESS/v1", # copy from AI Router -> Quick start
api_key="gx-YOUR_API_KEY", # or os.environ["GALAXIUM_API_KEY"]
)
resp = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
JavaScript / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://YOUR-PORTAL-ADDRESS/v1", // copy from AI Router -> Quick start
apiKey: process.env.GALAXIUM_API_KEY, // gx-...
});
const resp = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(resp.choices[0].message.content);
Other apps and tools
In any app that asks for an OpenAI connection, enter the base URL as the base URL (sometimes called "API host" or "OpenAI-compatible endpoint") and your gx- key as the API key. Many tools also read the OPENAI_BASE_URL and OPENAI_API_KEY environment variables.
Streaming
Pass stream=True (Python) or stream: true (JavaScript, curl). Responses then arrive as server-sent events, just as with OpenAI.
Supported endpoints
| Endpoint | Purpose |
|---|---|
GET /v1/models | List the models your key can use |
GET /v1/models/{id} | Details and price of one model |
POST /v1/chat/completions | Chat completions, with or without streaming |
POST /v1/messages | The same models in the Anthropic Messages format, for apps built for it |
GET /v1/credits | Your remaining credit balance |
Send the key as Authorization: Bearer gx-…. Apps built for the Anthropic format can send it as the x-api-key header instead.
Other endpoints, such as embeddings, return 404 unknown_endpoint.
Troubleshooting
| Status | Meaning |
|---|---|
| 400 | The request is malformed or too big for the model. The error message says which field. |
| 401 | Missing, invalid or revoked key, or the account is suspended. Send Authorization: Bearer gx-…. |
| 402 | Your credit balance is empty, or too low for what this request could cost. Top up, or lower max_tokens. |
| 403 | This key isn't allowed to use that model. |
| 404 | Unknown model ID. Check Models. |
| 429 | Too many requests running at once, or this key reached its monthly credit cap. The message says which. |
Failed requests aren't charged. If your app disconnects in the middle of a streamed answer, the part already generated is charged. More on limits: AI Router usage, balance and limits. Try models without writing code in the Playground.