The OpenAI SDK is the de facto standard for integrating large language models into Python and Node.js applications. It manages connection pooling, automatic retries, streaming Server-Sent Events, and request serialization so you can focus on prompts and logic rather than debugging HTTP. Because Oxlo.ai implements the same REST schema, you can repoint your existing client to Oxlo.ai and immediately run open-source models such as Llama 3.3 70B, DeepSeek R1 671B MoE, and Qwen 3 32B without touching your application logic.
Installation and Setup
Install the official library from PyPI or npm. You do not need a separate Oxlo.ai SDK.
# Python
pip install openai
# Node.js
npm install openai
Create an environment variable for your API key. If you are using Oxlo.ai, copy your key from the dashboard and export it.
export OXLO_API_KEY="oxlo_..."
Making Your First Request
A chat completion follows the same pattern everywhere. You instantiate a client, define a messages array, and call chat.completions.create.
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Explain request-based pricing in one sentence."}]
)
print(response.choices[0].message.content)
Switching to Oxlo.ai
Oxlo.ai is a drop-in replacement. Change the base_url to https://api.oxlo.ai/v1, swap in an Oxlo.ai model name, and pass your Oxlo.ai key. Every other parameter, from temperature to max_tokens, behaves identically.
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ["OXLO_API_KEY"]
)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[{"role": "user", "content": "Explain request-based pricing in one sentence."}]
)
print(response.choices[0].message.content)
In Node.js the pattern is identical.
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.oxlo.ai/v1',
apiKey: process.env.OXLO_API_KEY,
});
const response = await client.chat.completions.create({
model: 'llama-3.3-70b',
messages: [{ role: 'user', content: 'Explain request-based pricing in one sentence.' }],
});
console.log(response.choices[0].message.content);
This same one-line swap works for embeddings, image generation, audio transcription, and text-to-speech. Oxlo.ai supports the full endpoint set: chat/completions, embeddings, images/generations, audio/transcriptions, and audio/speech. There are no cold starts on popular models, so the first request returns as quickly as the hundredth.
Streaming, Tool Use, and JSON Mode
The SDK abstracts streaming SSE parsing, function dispatch, and constrained decoding. Oxlo.ai supports these features on all compatible models.
Streaming. Set stream=True and iterate over chunks. The client handles reconnection and buffering automatically.
stream = client.chat.completions.create(
model="deepseek-r1-671b",
messages=[{"role": "user", "content": "Write a Python function that flattens a nested list."}],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Function calling. Define your tools in the OpenAI schema and attach them to the request. Oxlo.ai routes the model output back through the same tool_calls object.
JSON mode. Pass response_format={"type": "json_object"} to receive validated JSON without extra parsing logic.
Vision and Multimodal Inputs
The SDK accepts image URLs or base64 strings inside the messages array. Oxlo.ai hosts vision-capable models such as Gemma 3 27B and Kimi VL A3B, so you can run visual question answering or document extraction without changing your request shape.
response = client.chat.completions.create(
model="gemma-3-27b",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/chart.png"}}
]
}
]
)
Request Pricing and Cost Control
Token-based billing means that every word in your prompt and every turn in your agent loop adds to the bill. For long-context retrieval, code review, or autonomous agents, costs scale linearly with input length.
Oxlo.ai uses request-based pricing instead: one flat cost per API request regardless of prompt length. For long-context and agentic workloads, this can be 10-100x cheaper than token-based providers. Oxlo.ai offers a free tier at $0 per month with 60 requests per day across 16+ models and a 7-day full-access trial, plus Pro and Premium plans for production traffic. See the exact tiers on the Oxlo.ai pricing page.
Next Steps
Sign up at Oxlo.ai, generate an API key, and point your OpenAI client to https://api.oxlo.ai/v1. With 45+ models spanning chat, reasoning, code, vision, image generation, audio, and embeddings, you can test DeepSeek V4 Flash, Kimi K2.6, GLM 5, or Oxlo.ai Coder Fast without refactoring a single line of client code. If you are migrating from a token-based provider, Oxlo.ai's flat request model gives you predictable costs no matter how large your prompts
Top comments (0)