Use Claude and GPT models through one OpenAI-style endpoint.
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.
# 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": "YOUR_MODEL_NAME",
"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="YOUR_MODEL_NAME",
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: "YOUR_MODEL_NAME",
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="YOUR_MODEL_NAME",
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
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="YOUR_MODEL_NAME",
)
print(llm.invoke("Explain API gateways in 2 sentences.").content)
LlamaIndex
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="YOUR_MODEL_NAME",
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
Call GET /v1/models with your API key.
Pick a model ID from the response.
Run one small chat request with it.
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.