Skip to content

New: DeepSeek V4.1 Flash Derisked. In chat and on the API.

See modelsWhat's newReport a bug
Open chat
All IDE and SDK guides

OpenAI and Anthropic SDKs

Use the Vani API with the OpenAI and Anthropic SDKs

Set the base URL and key in the official Python and JavaScript SDKs.

OpenAI SDK base URL
https://api.vani.ai/v1
Anthropic SDK base URL
https://api.vani.ai (no /v1)
Auth
Bearer (OpenAI SDKs) · x-api-key (Anthropic SDKs)
Example model
openai/gpt-6-sol

Checked against the vendor's documentation on 2 October 2026. Need a key? Create one in the API console.

On this pageBefore you start

Before you start

  • OpenAI SDKs: Python 3.10+ (pip install openai) or Node.js 22+ (npm install openai).
  • Anthropic SDKs: Python 3.10+ (pip install anthropic) or Node.js 20+ (npm install @anthropic-ai/sdk).
  • Vani's Responses API is stateless: send the conversation in input each time instead of previous_response_id.
  • No embeddings, legacy completions or Azure-style endpoints.

Environment variables

Set your key once as VANI_API_KEY: the examples below read it. Both SDK families also read their base URL and key from the environment, so OpenAI() and Anthropic() work without arguments. Note the different base URLs.

Shell

Shell

# Your Vani API key, read by every example below
export VANI_API_KEY="vani_YOUR_API_KEY"

# OpenAI SDKs: base URL includes /v1
export OPENAI_API_KEY="$VANI_API_KEY"
export OPENAI_BASE_URL="https://api.vani.ai/v1"

# Anthropic SDKs: base URL without /v1
export ANTHROPIC_API_KEY="$VANI_API_KEY"
export ANTHROPIC_BASE_URL="https://api.vani.ai"

Automatic retries

Turn automatic retries off: max_retries=0 in Python, maxRetries: 0 in JavaScript, as in the examples below. By default the SDKs repeat a request that failed or timed out up to 2 more times, and a request with an uncertain result may already have been billed, so each repeat can be billed again. Check usage and request status before repeating a request.

OpenAI SDKs

Python

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["VANI_API_KEY"],
    base_url="https://api.vani.ai/v1",
    max_retries=0,  # Avoid automatic replays after an uncertain response.
)

stream = client.chat.completions.create(
    model="openai/gpt-6-sol",  # or openai/gpt-6-sol-fast, deepseek/deepseek-v4.1-flash
    messages=[{"role": "user", "content": "Explain SSE in one sentence."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

# Responses: stateless, so resend the history
resp = client.responses.create(
    model="openai/gpt-6-sol-fast",
    input=[
        {"role": "user", "content": "My name is Ada."},
        {"role": "assistant", "content": "Nice to meet you, Ada."},
        {"role": "user", "content": "What is my name?"},
    ],
)
print(resp.output_text)

print([m.id for m in client.models.list()])
JavaScript

JavaScript / TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.VANI_API_KEY,
  baseURL: "https://api.vani.ai/v1",
  maxRetries: 0, // Avoid automatic replays after an uncertain response.
});

const stream = await client.chat.completions.create({
  model: "openai/gpt-6-sol",
  messages: [{ role: "user", content: "Hello from Vani" }],
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");

Anthropic SDKs

The Anthropic SDKs call Vani's Messages endpoint. max_tokens is required.

Python

Python

import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["VANI_API_KEY"],
    base_url="https://api.vani.ai",
    max_retries=0,  # Avoid automatic replays after an uncertain response.
)

message = client.messages.create(
    model="anthropic/claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello from Vani"}],
)
print(message.content)

with client.messages.stream(
    model="deepseek/deepseek-v4.1-flash",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Stream a haiku."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
JavaScript

TypeScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.VANI_API_KEY,
  baseURL: "https://api.vani.ai",
  maxRetries: 0, // Avoid automatic replays after an uncertain response.
});

const message = await client.messages.create({
  model: "anthropic/claude-sonnet-5.5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello from Vani" }],
});
console.log(message.content);

Note

List model ids with the OpenAI SDK or curl: Vani's /v1/models answers in the OpenAI shape.

Note

If ANTHROPIC_AUTH_TOKEN is set in your environment, the SDK sends it as an extra Bearer header; unset it when it holds another credential.

Troubleshooting

404 from an OpenAI SDK
The base URL must be https://api.vani.ai/v1. Check that OPENAI_BASE_URL is not set to something else.
404 from an Anthropic SDK (path /v1/v1/messages)
Use https://api.vani.ai without /v1: the SDK appends /v1/messages.
400: max_tokens is required
Always pass max_tokens to the Messages API.
A Responses follow-up fails with previous_response_id
Vani does not store responses. Resend the conversation in input, or use Chat Completions.
401 Unauthorized
Use a Vani key (it starts with vani_) from the API console, not a key from another provider. Vani accepts Authorization: Bearer <key> or x-api-key: <key>; the Azure-style api-key header is not accepted. Check that no space or line break was pasted with the key.
404 model_not_available, or "model not found"
Use the exact vendor-prefixed id, for example openai/gpt-6-sol. List the ids your key can use with curl https://api.vani.ai/v1/models -H "Authorization: Bearer $VANI_API_KEY".
402 api_insufficient_balance
Prepaid API keys need funds in the console's Billing page. Subscription keys (created from Vani Chat) draw on your plan instead.

Still stuck? Check service status or the API error reference.

Sources