OpenAI · SDK

OpenAI SDK

The official OpenAI SDKs for Python and Node accept a custom endpoint. Set base_url to your NextModel endpoint, keep the key in the environment, and the rest of your code stays unchanged.

Quick start

  1. Get your NextModel API Key

    Create a key in the NextModel console and export it as NEXTMODEL_API_KEY so the snippets below can read it.

    Shell
    export NEXTMODEL_API_KEY=<YOUR_API_KEY>
  2. Point the Python client at NextModel

    The only change from the default OpenAI setup is base_url.

    Official docs

    Python
    import os
    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://api.nextmodel.app/v1",
        api_key=os.environ["NEXTMODEL_API_KEY"],
    )
    
    resp = client.chat.completions.create(
        model="claude-sonnet-4-5",
        messages=[{"role": "user", "content": "Say hello in one sentence."}],
    )
    print(resp.choices[0].message.content)
  3. Or the Node client

    Same story in TypeScript: baseURL is the one new argument.

    Official docs

    TypeScript
    import OpenAI from "openai";
    
    const client = new OpenAI({
      baseURL: "https://api.nextmodel.app/v1",
      apiKey: process.env.NEXTMODEL_API_KEY,
    });
    
    const resp = await client.chat.completions.create({
      model: "claude-sonnet-4-5",
      messages: [{ role: "user", content: "Say hello in one sentence." }],
    });
    console.log(resp.choices[0].message.content);
  4. Keep the key out of your code

    Both clients read the key from the environment — load it with dotenv locally or your platform's secret manager in production.

Example prompts

Prompts
Classify this support ticket as billing, bug report, or how-to, and answer it.
Draft a three-paragraph product description from these bullet points.

FAQ

Which SDK versions support base_url?

Every current openai-python and openai-node release accepts base_url / baseURL in the client constructor — including the version your project already uses.

Is streaming supported?

Yes. Pass stream=True in Python or stream: true in Node and consume the response as a chunk iterator, exactly as with the default endpoint.

Can I hardcode the key for a quick test?

Prefer the environment variable even locally — the snippets read NEXTMODEL_API_KEY so nothing sensitive lands in git.

Troubleshooting

AuthenticationError 401

The process never saw NEXTMODEL_API_KEY. Echo the variable in the same shell — or check your .env loading — before retrying.

404 on chat.completions

base_url must end in /v1 exactly once. A missing /v1 or a doubled /v1/v1 both surface as not-found errors.

Other agents

CLIOpenAI

Codex CLI

OpenAI's terminal coding agent, pointed at NextModel.

Codex CLI reads model providers from ~/.codex/config.toml. Add one provider block that points at your NextModel base URL, export your key, and every codex run routes through NextModel.

Codex CLI
IDEAnysphere

Cursor

The AI-first IDE, wired to your own endpoint.

Cursor supports bring-your-own-key for OpenAI-compatible endpoints. Paste your NextModel key under Settings → Models and point the OpenAI provider's base URL at NextModel so OpenAI-format requests go there.

Cursor
IDECline

Cline

Autonomous coding inside VS Code, on your own key.

Cline is a VS Code extension that plans and edits code with your approval at each step. Its OpenAI Compatible provider accepts any endpoint, so NextModel is one form away.

Cline
DesktopCherry Studio

Cherry Studio

A desktop chat client that speaks OpenAI out of the box.

Cherry Studio manages model providers as services. Add NextModel once as an OpenAI-compatible provider and it sits next to the services you already use.

Cherry Studio