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

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

EndpointPurpose
GET /v1/modelsList the models your key can use
GET /v1/models/{id}Details and price of one model
POST /v1/chat/completionsChat completions, with or without streaming
POST /v1/messagesThe same models in the Anthropic Messages format, for apps built for it
GET /v1/creditsYour 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

StatusMeaning
400The request is malformed or too big for the model. The error message says which field.
401Missing, invalid or revoked key, or the account is suspended. Send Authorization: Bearer gx-….
402Your credit balance is empty, or too low for what this request could cost. Top up, or lower max_tokens.
403This key isn't allowed to use that model.
404Unknown model ID. Check Models.
429Too 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.