$LLMAI Docs

OpenAI SDK

Use LLMAI with the official OpenAI Python and Node.js SDKs — no new dependencies required.

How It Works

Because LLMAI speaks the OpenAI Chat Completions protocol, the official openai SDK connects to it with two configuration changes:

  • Set base_url to https://api.llmai.dev/v1
  • Set api_key to your LLMAI key

Everything else — method names, response objects, streaming helpers — stays identical.


Python

Install the SDK

pip install openai

Configure and Send a Request

from openai import OpenAI

llmai = OpenAI(
    base_url="https://api.llmai.dev/v1",
    api_key="YOUR_LLMAI_API_KEY",
)

response = llmai.chat.completions.create(
    model="gpt-5.4",
    messages=[
        {"role": "system", "content": "You are a concise technical assistant."},
        {"role": "user",   "content": "What is the difference between REST and GraphQL?"},
    ],
)

print(response.choices[0].message.content)

Streaming in Python

stream = llmai.chat.completions.create(
    model="deepseek-v3.2",
    messages=[{"role": "user", "content": "Walk me through writing a binary search."}],
    stream=True,
)

for chunk in stream:
    fragment = chunk.choices[0].delta.content
    if fragment:
        print(fragment, end="", flush=True)
print()  # newline after stream ends

Load Credentials from the Environment

Store your key and base URL as environment variables so they never appear in source code:

export OPENAI_API_KEY="sk-llmaai-your-key-here"
export OPENAI_BASE_URL="https://api.llmai.dev/v1"

Then instantiate the client without arguments — the SDK picks them up automatically:

from openai import OpenAI

llmai = OpenAI()  # reads OPENAI_API_KEY and OPENAI_BASE_URL from environment

Or put them in a .env file and load with python-dotenv:

OPENAI_API_KEY=sk-llmaai-your-key-here
OPENAI_BASE_URL=https://api.llmai.dev/v1

Node.js / TypeScript

Install the SDK

npm install openai

Configure and Send a Request

import OpenAI from "openai";

const llmai = new OpenAI({
  baseURL: "https://api.llmai.dev/v1",
  apiKey: process.env.LLMAI_API_KEY,
});

const result = await llmai.chat.completions.create({
  model: "gemini-3.1-pro-preview",
  messages: [
    { role: "user", content: "Summarize the main benefits of containerisation." },
  ],
});

console.log(result.choices[0].message.content);

Streaming in Node.js

const stream = await llmai.chat.completions.create({
  model: "glm-5-turbo",
  messages: [{ role: "user", content: "Explain async/await in JavaScript." }],
  stream: true,
});

for await (const chunk of stream) {
  const text = chunk.choices[0]?.delta?.content ?? "";
  process.stdout.write(text);
}
process.stdout.write("\n");

Environment Variables (.env)

LLMAI_API_KEY=sk-llmaai-your-key-here
OPENAI_BASE_URL=https://api.llmai.dev/v1

Changing Models at Runtime

Swapping providers is a single-field change — no client reconfiguration needed:

# Use OpenAI's flagship
response = llmai.chat.completions.create(model="gpt-5.4", messages=[...])

# Switch to Google's long-context model
response = llmai.chat.completions.create(model="gemini-3.1-pro-preview", messages=[...])

# Switch to a cost-efficient option
response = llmai.chat.completions.create(model="deepseek-v3.2", messages=[...])

See the Models page for every available slug.

On this page