Docs / Connect

Connect → OpenAI SDK

Use AxForge with the OpenAI SDK

The official OpenAI SDKs take a base-URL option. Set it to https://api.axforge.ai/v1, use your AxForge key, and the rest of your code is unchanged — chat, streaming, tools, vision and embeddings all work against the same client.

Python

Python
# pip install openai — the official SDK, unchanged
from openai import OpenAI

client = OpenAI(
    base_url="https://api.axforge.ai/v1",   # or set OPENAI_BASE_URL
    api_key="YOUR_AXFORGE_KEY",             # or set OPENAI_API_KEY
)

resp = client.chat.completions.create(
    model="chat",
    messages=[{"role": "user", "content": "Hello from Stockholm"}],
)
print(resp.choices[0].message.content)
print(resp.usage)   # token counts, for your own accounting

Streaming

stream = client.chat.completions.create(
    model="chat", stream=True,
    messages=[{"role": "user", "content": "Count to five"}],
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Embeddings

e = client.embeddings.create(model="embeddings", input="a sentence to embed")
print(len(e.data[0].embedding))   # 1024

Node / TypeScript

Node
// npm i openai
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.axforge.ai/v1",   // or OPENAI_BASE_URL
  apiKey: process.env.AXFORGE_API_KEY,       // or OPENAI_API_KEY
});

const resp = await client.chat.completions.create({
  model: "chat",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(resp.choices[0].message.content);

Tip — use chat.completions. This SDK's client.chat.completions.create hits the widely-supported Chat Completions API and is the path shown here. AxForge also serves the newer Responses API (client.responses.create/v1/responses) natively, so either works — see Codex & Claude Code.

Model names

Use a stable role name like chat or embeddings, or an exact version like qwen3.8-27b-nvfp4 — both resolve to the same served model. Call client.models.list() (GET /v1/models) for the live catalogue, or see Models & pricing.

Keep your data in the EU

Every key is pinned to an EU region, and you can force one per request with a default header:

client = OpenAI(
    base_url="https://api.axforge.ai/v1", api_key="YOUR_AXFORGE_KEY",
)  # the region is pinned on the key — nothing to set per request

Prompts and completions are processed in memory and never retained — see Regions & data handling.

Check that it worked

Two things, and the second is the one that proves it end to end:

  1. The response object carries a usage block with token counts. That is the API answering, not a stub.
  2. response.model is an AxForge model id, which tells you the base URL took effect.
  3. The call appears in the console at Billing & usage within a minute or two. Nothing else confirms that your key reached our API — a reply alone could be a cache or another provider.

When it does not work

What you seeWhat it meansFix
AuthenticationErrorthe key is wrong or from the other environmentconfirm it with the self-test before blaming the SDK
NotFoundError / 404the base URL is missing /v1, or the model id is not one we serveids are on Models & pricing
It reaches OpenAI insteadbase_url was not applied to the client you actually usedset it on the client you call, not a second one

Run the self-test first when you are unsure — it says in one click whether the problem is your key, your quota or us, so you know whether the tool is worth debugging at all.

Anything unclear on this page?

Ask on the forum — the answer helps the next person too.

Ask about this page
© 2026 AxForge · EU-hosted AI infrastructure Docs Models For AI axforge.ai Pricing Trust Acceptable use Community guidelines