questions/Python

Nova-3 Python example?

Here's a minimal Python example calling Nova-3 through AIgateway's OpenAI-compatible API. Install `pip install aigateway-py openai`, create an sk-aig-... key at aigateway.sh, then instantiate the OpenAI client with base_url="https://api.aigateway.sh/v1" and call chat.completions.create with model="deepgram/nova-3". Works with streaming, tool calling, and async out of the box.

How it works

1. Install the SDKs

pip install aigateway-py openai. The OpenAI SDK handles chat, embeddings, images, and audio endpoints — which covers Nova-3 end-to-end. aigateway-py adds gateway-specific primitives: sub-account key minting, evals, replays, async jobs, and webhook signature verification.

2. Construct the client once, call the right endpoint

Use client.audio.transcriptions.create with model="deepgram/nova-3". AIgateway matches OpenAI's request and response shape exactly, so autocompletion, type hints, and error handling all work.

3. Stream, batch, or tool-call — same API

Set stream=True for server-sent events. Pass tools=[...] for function calling. The OpenAI SDK's helpers (with_raw_response, with_streaming_response, runnable tools) all work against AIgateway unchanged because the wire format is identical.

Code example

Python
# pip install aigateway-py openai
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aigateway.sh/v1",
    api_key="sk-aig-...",
)

with open("clip.mp3", "rb") as f:
    r = client.audio.transcriptions.create(model="deepgram/nova-3", file=f)
print(r.text)
Node / TypeScript
import OpenAI from "openai";
import fs from "node:fs";

const client = new OpenAI({
  baseURL: "https://api.aigateway.sh/v1",
  apiKey: process.env.AIGATEWAY_KEY,
});

const r = await client.audio.transcriptions.create({
  model: "deepgram/nova-3",
  file: fs.createReadStream("clip.mp3"),
});
console.log(r.text);

Related

FAQ

What Python SDK should I use with Nova-3?

The official OpenAI Python SDK (openai package) works unchanged. Pair with aigateway-py for sub-account key minting, evals, replays, and webhook signature verification.

How do I stream Nova-3 responses in Python?

Pass stream=True to chat.completions.create and iterate: for chunk in stream: print(chunk.choices[0].delta.content, end=""). Works identically to OpenAI.

Can I use async Python with Nova-3?

Yes — import AsyncOpenAI from openai, await client.chat.completions.create(...). AIgateway supports concurrent connections and HTTP/2.

Does Nova-3 work with LangChain and LlamaIndex?

Yes. Use ChatOpenAI(base_url="https://api.aigateway.sh/v1", api_key="sk-aig-...", model="deepgram/nova-3"). LlamaIndex: OpenAI(api_base="https://api.aigateway.sh/v1", api_key="sk-aig-...", model="deepgram/nova-3").

TRY IT NOW

One key, every model. Free tier, no card.

Get an AIgateway keyOpen the playground