Documentation / Connect

Connect → OpenAI SDK and curl

Use AxForge with the OpenAI SDK and curl

The official OpenAI SDKs take a base URL. Set it to https://api.axforge.ai/v1, use your AxForge key, and the rest of your code stays as it is: chat, streaming, tools, embeddings.

Before you start
  • An AxForge API key, in the environment variable AXFORGE_API_KEY. Get one (a minute).
  • Python 3.9 or newer, or Node.js 18 or newer. Run with openai 2.54.0 (Python) and openai 7.36.0 (Node) on 2026-10-17.

The first call

  1. Python

    pip install openai
    import os
    from openai import OpenAI
    
    client = OpenAI(base_url="https://api.axforge.ai/v1", api_key=os.environ["AXFORGE_API_KEY"])
    
    reply = client.chat.completions.create(
        model="qwen3.8-27b",
        messages=[{"role": "user", "content": "Say hello in five words"}],
    )
    print(reply.choices[0].message.content)
    hello.py shown in a terminal and run, printing a five-word hello from qwen3.8-27b
  2. Node

    npm install openai
    import OpenAI from "openai";
    
    const client = new OpenAI({ baseURL: "https://api.axforge.ai/v1", apiKey: process.env.AXFORGE_API_KEY });
    
    const reply = await client.chat.completions.create({
      model: "qwen3.8-27b",
      messages: [{ role: "user", content: "Say hello in five words" }],
    });
    console.log(reply.choices[0].message.content);
    hello.mjs shown in a terminal and run with node, printing a five-word hello
  3. curl

    No SDK at all: the same call as plain HTTP.

    curl https://api.axforge.ai/v1/chat/completions \
      -H "Authorization: Bearer $AXFORGE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"model":"qwen3.8-27b","messages":[{"role":"user","content":"Say hello in five words"}]}'

    The reply names the model that answered and the tokens it used:

    A curl call to AxForge in a terminal, its reply showing the model qwen3.8-27b, the answer and the token usage

Streaming

The words arrive as they are written:

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.axforge.ai/v1", api_key=os.environ["AXFORGE_API_KEY"])

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

Embeddings

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

More on Embeddings.

The Responses API

AxForge also serves OpenAI's newer Responses API, so client.responses.create works with the same client:

r = client.responses.create(model="qwen3.8-27b", input="Say hello in five words")
print(r.output_text)

The settings

SettingValue
base_url (Python) · baseURL (Node)https://api.axforge.ai/v1
api_key · apiKeyyour AxForge key
modelqwen3.8-27b, glm-5.3-flash or mimo-v2.6-flash

Which model for what: qwen3.8-27b is the everyday default and reads images, glm-5.3-flash thinks before it answers, mimo-v2.6-flash is the fastest. Every model id is on Models, and client.models.list() returns them too.

Check that it works

reply.model is the AxForge model you asked for and reply.usage has token counts. The call shows in the console under API Keys → Recent calls within a minute.

When it does not work

Not sure which it is? The connection doctor makes seven small checks on your key and names the fix: irm https://dev.axforge.ai/assets/axforge-doctor.ps1 | iex in PowerShell, curl -fsSL https://dev.axforge.ai/assets/axforge-doctor.sh | bash on macOS and Linux.

What you seeWhat it meansFix
AuthenticationError, 401 "Invalid API key. Create one at https://console.axforge.ai/keys."the key was refusedcheck AXFORGE_API_KEY holds the whole key, or make a new one
KeyError: 'AXFORGE_API_KEY'the variable is not set in this terminalset it as on Get your API key
NotFoundError, 404the base URL has no /v1use https://api.axforge.ai/v1
It reaches OpenAI insteadthe base URL is set on another client than the one you callset it on the client you use

Test a call says in one click whether a problem is your key, your balance or us.

Ask on the forum Markdown For AI Updated 2026-11-06

Anything unclear on this page?

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

Ask about this page