# OpenAI SDK


    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:

      - The response object carries a `usage` block with token counts. That is the API answering, not a stub.
- `response.model` is an AxForge model id, which tells you the base URL took effect.

      - 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 see | What it means | Fix |  |

        | `AuthenticationError` | the key is wrong or from the other environment | confirm it with the self-test before blaming the SDK |  |

        | `NotFoundError` / 404 | the base URL is missing `/v1`, or the model id is not one we serve | ids are on Models & pricing |  |

        | It reaches OpenAI instead | `base_url` was not applied to the client you actually used | set 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.

      &larr; Use with your stack
      Vercel AI SDK &rarr;



Source: https://axforge.ai/docs/connect/openai-sdk/
