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
inputeach time instead ofprevious_response_id. - No embeddings, legacy completions or Azure-style endpoints.
Environment variables
Both SDK families read their base URL and key from the environment. Note the different base URLs.
Shell
Shell
# OpenAI SDKs: base URL includes /v1
export OPENAI_API_KEY="vani_YOUR_API_KEY"
export OPENAI_BASE_URL="https://api.vani.ai/v1"
# Anthropic SDKs: base URL without /v1
export ANTHROPIC_API_KEY="vani_YOUR_API_KEY"
export ANTHROPIC_BASE_URL="https://api.vani.ai"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")
stream = client.chat.completions.create(
model="openai/gpt-6-sol", # or openai/gpt-6-sol-fast, meta/muse-spark-1.3
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" });
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")
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="meta/muse-spark-1.3",
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" });
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 thatOPENAI_BASE_URLis not set to something else. - 404 from an Anthropic SDK (path /v1/v1/messages)
- Use
https://api.vani.aiwithout/v1: the SDK appends/v1/messages. - 400: max_tokens is required
- Always pass
max_tokensto 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 acceptsAuthorization: Bearer <key>orx-api-key: <key>; the Azure-styleapi-keyheader 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 withcurl 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.