← Back to comparisons
RANA vs OpenAI SDK
The OpenAI SDK is great for OpenAI models. RANA gives you the same experience across all providers, plus production features you actually need.
5+
Providers Supported
1
Unified API
Auto
Tool Execution
Built-in
Fallbacks
| Feature | OpenAI SDK | RANA |
|---|---|---|
OpenAI Models Both support all OpenAI models | ✓ | ✓ |
Anthropic Models RANA supports Claude models natively | ✗ | ✓ |
Google Models RANA supports Gemini models | ✗ | ✓ |
Local Models (Ollama) RANA supports local models out of the box | ✗ | ✓ |
Unified API One API for all providers | ✗ | ✓ |
Automatic Tool Execution RANA runs tools automatically | ✗ | ✓ |
Cost Tracking RANA tracks costs across providers | ✗ | ✓ |
Built-in Testing RANA includes testing utilities | ✗ | ✓ |
Automatic Fallbacks RANA falls back between providers | ✗ | ✓ |
Security Features RANA includes injection detection, PII filtering | ✗ | ✓ |
Basic Chat Completion
OpenAI SDK15 lines
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const completion = await openai.chat.completions.create({
model: 'gpt-4',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
],
});
console.log(completion.choices[0].message.content);RANA9 lines
import { createRana } from '@rana/core';
const rana = createRana();
const response = await rana
.system('You are a helpful assistant.')
.chat('Hello!');
console.log(response.content);Multi-Provider Support
OpenAI SDK19 lines
// OpenAI SDK - only supports OpenAI
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';
// Need separate clients for each provider
const openai = new OpenAI();
const anthropic = new Anthropic();
// Different APIs for each
const openaiResponse = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello' }],
});
const anthropicResponse = await anthropic.messages.create({
model: 'claude-3-sonnet-20240229',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});RANA15 lines
import { createRana } from '@rana/core';
const rana = createRana();
// Same API for all providers
const gpt4 = await rana.model('gpt-4').chat('Hello');
const claude = await rana.model('claude-3-sonnet').chat('Hello');
const gemini = await rana.model('gemini-pro').chat('Hello');
// Switch providers with one line
const response = await rana
.model(process.env.MODEL || 'gpt-4')
.chat('Hello');Tool Calling
OpenAI SDK36 lines
import OpenAI from 'openai';
const openai = new OpenAI();
const tools = [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the weather in a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city name',
},
},
required: ['location'],
},
},
},
];
const completion = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Weather in SF?' }],
tools,
});
// Manually handle tool calls
const toolCall = completion.choices[0].message.tool_calls?.[0];
if (toolCall) {
const args = JSON.parse(toolCall.function.arguments);
// Execute function, make another API call...
}RANA20 lines
import { createRana, createTool } from '@rana/core';
const rana = createRana();
const weather = createTool({
name: 'get_weather',
description: 'Get the weather in a location',
parameters: { location: { type: 'string' } },
handler: async ({ location }) => {
return `Weather in ${location}: Sunny, 72°F`;
},
});
// RANA automatically executes tools
const response = await rana
.tools([weather])
.chat('Weather in SF?');
// Response includes the result directly
console.log(response.content);Streaming
OpenAI SDK16 lines
import OpenAI from 'openai';
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Tell a story' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}RANA7 lines
import { createRana } from '@rana/core';
const rana = createRana();
for await (const chunk of rana.stream('Tell a story')) {
process.stdout.write(chunk);
}The Multi-Provider Advantage
Automatic Fallbacks
If OpenAI is down, automatically switch to Anthropic or Google. Zero downtime, zero code changes.
Cost Optimization
Route simple queries to cheaper models automatically. Use GPT-4 only when needed.
Best Model Selection
Different models excel at different tasks. Use Claude for analysis, GPT-4 for code, Gemini for multimodal.
When to Choose Each
Choose RANA if you:
- ✓Want flexibility to use multiple providers
- ✓Need automatic fallbacks and reliability
- ✓Want built-in cost tracking and testing
- ✓Prefer cleaner, simpler APIs
Choose OpenAI SDK if you:
- •Only ever need OpenAI models
- •Need direct access to OpenAI-specific features
- •Have existing code using OpenAI SDK