OpenAI TypeScript SDK with Novita AI: Base URL, Examples, and Agent Sandbox

OpenAI TypeScript SDK with Novita AI: Base URL, Examples, and Agent Sandbox

If your stack already uses an AI SDK built around OpenAI, Novita AI is mostly a base URL, API key, and model ID change. The official OpenAI TypeScript SDK supports custom endpoints, and Novita’s docs expose OpenAI-compatible chat completions at https://api.novita.ai/openai/v1/chat/completions, so the first migration step is small.

That makes Novita a practical fit when you want to keep your existing SDK workflow and test a different model backend without rewriting your app.

OpenAI TypeScript SDK with Novita AI: What Changes and What Stays the Same

ItemOpenAI SDK defaultNovita AI setupWhy it matters
Client libraryopenaiopenaiKeep the same TypeScript package.
Base URLOpenAI endpointhttps://api.novita.ai/openaiThe SDK adds the versioned path.
API keyOpenAI keyNovita API keyAuthentication changes, not the call shape.
Model nameOpenAI model IDNovita model IDTreat model IDs as provider-specific.
First requestchat.completions.create()chat.completions.create()Start with the same request pattern.

How to Set Up the OpenAI TypeScript SDK with Novita AI

Install the SDK:

npm install openai

Then point it at Novita:

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.NOVITA_API_KEY,
  baseURL: "https://api.novita.ai/openai",
});

const response = await client.chat.completions.create({
  model: "openai/gpt-oss-120b",
  messages: [
    { role: "system", content: "You are a concise technical assistant." },
    { role: "user", content: "Show me the shortest Novita SDK setup in TypeScript." },
  ],
});

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

Start with chat completions. Novita’s public docs currently document the OpenAI-compatible chat completions path, so that is the safest first test.

Python OpenAI SDK Equivalent on Novita AI

The same pattern works in Python:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["NOVITA_API_KEY"],
    base_url="https://api.novita.ai/openai",
)

response = client.chat.completions.create(
    model="openai/gpt-oss-120b",
    messages=[
        {"role": "user", "content": "Explain the Novita setup in one paragraph."}
    ],
)

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

When to Use Novita Agent Sandbox with the OpenAI SDK

Use the SDK for model calls, then use Novita Agent Sandbox when the workflow needs code execution, browser actions, or file work in isolation. That split keeps inference and execution separate, which is the right shape for coding agents.

OpenAI SDK Migration Tips for a Better Developer Experience

  • Use https://api.novita.ai/openai as the SDK base URL. The OpenAI SDK appends the versioned path for you, so you do not need to add /v1 manually.
  • Swap in a Novita-supported model ID before testing. The SDK code can stay the same, but model IDs are provider-specific.
  • Treat OpenAI compatibility as a migration shortcut, not a guarantee that every newer platform feature behaves the same way. Check the current Novita docs before rollout.
  • If your workflow runs generated code, file operations, or browser actions, move execution into Agent Sandbox instead of your local machine.

FAQ

Is the OpenAI TypeScript SDK enough by itself?

Yes for model calls. No for isolated execution. If the app is agentic, pair it with Agent Sandbox.

Can I keep the same code in JavaScript and TypeScript?

Yes. The SDK usage is the same.

Read the Novita LLM API guide and the chat completions reference, then confirm the exact model ID in the model library before production use.