OpenAI-Compatible API

Use Claude and GPT models through one OpenAI-style endpoint.

Short answer

APIVAI's OpenAI-compatible API is at https://api.apivai.com/v1: point an OpenAI SDK or tool at it with an APIVAI key and call /v1/chat/completions, /v1/responses or /v1/models, with Claude and GPT model IDs on the same key. As of 2026-10-10, claude-sonnet-5-5 costs $0.77 / $3.82 per million input / output tokens and gpt-5.5 costs $0.77 / $4.56. Every model ID and its price is on the models page.

BASE URLhttps://api.apivai.com/v1

APIVAI speaks the OpenAI HTTP format, so tools and SDKs that accept a custom base URL work without custom integration code. Change the base URL and the key, keep the rest of your code.

Endpoints

Method and pathPurposeNotes
GET /v1/modelsList modelsCall this before hardcoding a model name.
POST /v1/chat/completionsChat completionsTakes an OpenAI-style messages array.
POST /v1/chat/completionsStreaming chatAdd "stream": true to receive server-sent events.
POST /v1/responsesResponses APIUsed by Codex CLI.

Headers

Authorization: Bearer YOUR_APIVAI_API_KEY Content-Type: application/json

Quick check with cURL

# 1) List the models available to your key curl https://api.apivai.com/v1/models \ -H "Authorization: Bearer $APIVAI_API_KEY" # 2) Send a minimal chat request curl https://api.apivai.com/v1/chat/completions \ -H "Authorization: Bearer $APIVAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Return one short sentence."}] }'

OpenAI SDK

Python

from openai import OpenAI client = OpenAI( api_key="YOUR_APIVAI_API_KEY", base_url="https://api.apivai.com/v1", ) resp = client.chat.completions.create( model="claude-sonnet-5-5", messages=[ {"role": "system", "content": "You are a concise technical assistant."}, {"role": "user", "content": "Explain API gateways in 2 sentences."}, ], temperature=0.2, ) print(resp.choices[0].message.content)

Node.js

import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.APIVAI_API_KEY, baseURL: "https://api.apivai.com/v1", }); const resp = await client.chat.completions.create({ model: "gpt-5.5", messages: [{ role: "user", content: "Explain API gateways in 2 sentences." }], }); console.log(resp.choices[0]?.message?.content);

Streaming

Set stream to true and read the response body incrementally. Chunks arrive as lines starting with "data:"; the stream ends with [DONE] or when the connection closes.

stream = client.chat.completions.create( model="claude-sonnet-5-5", messages=[{"role": "user", "content": "Write a short deployment checklist."}], stream=True, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")

Function calling

The standard two-step flow works: the model returns a tool call, you run the tool, then you send the result back for the final answer.

import json from openai import OpenAI client = OpenAI(base_url="https://api.apivai.com/v1", api_key="YOUR_APIVAI_API_KEY") MODEL = "claude-sonnet-5-5" TOOLS = [{ "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city.", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, }, }] messages = [{"role": "user", "content": "What's the weather in Tokyo?"}] first = client.chat.completions.create(model=MODEL, messages=messages, tools=TOOLS) choice = first.choices[0].message messages.append(choice) for call in choice.tool_calls or []: args = json.loads(call.function.arguments) messages.append({ "role": "tool", "tool_call_id": call.id, "content": json.dumps({"city": args["city"], "temp_c": 21}), }) final = client.chat.completions.create(model=MODEL, messages=messages, tools=TOOLS) print(final.choices[0].message.content)

Frameworks

LangChain

from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="https://api.apivai.com/v1", api_key="YOUR_APIVAI_API_KEY", model="claude-sonnet-5-5", ) print(llm.invoke("Explain API gateways in 2 sentences.").content)

LlamaIndex

from llama_index.llms.openai_like import OpenAILike llm = OpenAILike( model="claude-sonnet-5-5", api_base="https://api.apivai.com/v1", api_key="YOUR_APIVAI_API_KEY", is_chat_model=True, ) print(llm.complete("Explain API gateways in 2 sentences."))

Choosing a model

  1. Call GET /v1/models with your API key.
  2. Pick a model ID from the response.
  3. Run one small chat request with it.
  4. Only then put the model name into your application config.

What "compatible" means

The request style is intentionally familiar, but not every parameter of every OpenAI endpoint is supported in every context. When migrating an existing integration, start with the smallest request body, confirm the model, then add optional parameters one at a time.

Common errors

404 usually means /v1 is missing or doubled in the base URL; 401 means the key is missing or wrong; model_not_found means the model ID is not in your GET /v1/models response. Every error code with fixes: Claude API error codes.