ainative-openai
v1.0.0
Published
Drop-in replacement for the openai npm package — routes to AINative's free OpenAI-compatible API. Free Llama 3.3 70B, Qwen, DeepSeek models with zero config.
Maintainers
Keywords
Readme
ainative-openai
Drop-in replacement for the openai npm package — routes to AINative's free OpenAI-compatible API.
Get free access to Llama 3.3 70B, Qwen, DeepSeek, and more open-source models. Same API, zero config.
Quick Start
npm install ainative-openai openaiimport OpenAI from 'ainative-openai';
const client = new OpenAI();
const response = await client.chat.completions.create({
model: 'llama-3.3-70b',
messages: [{ role: 'user', content: 'Explain quantum computing in one paragraph.' }]
});
console.log(response.choices[0].message.content);That's it. No API key needed on first run — one is auto-provisioned for you.
Why?
| Feature | openai | ainative-openai |
|---------|----------|-------------------|
| Price | Pay per token | Free tier included |
| Models | OpenAI only | Llama 3.3 70B, Qwen, DeepSeek, + more |
| Setup | API key required | Zero config (auto-provisions) |
| API | OpenAI API | Same OpenAI API |
| Streaming | Yes | Yes |
| Tool calling | Yes | Yes |
| TypeScript | Yes | Yes (inherits from openai) |
How It Works
ainative-openai wraps the official openai npm package and:
- Points
baseURLto AINative's OpenAI-compatible API (https://api.ainative.studio/api/v1) - Auto-provisions a free account on first use if no API key is found
- Saves credentials to
~/.ainative/config.json,.env, and.mcp.json
Everything else — streaming, tool calling, TypeScript types, error handling — comes directly from the openai package.
Available Models (Free Tier)
| Model | Best For |
|-------|----------|
| llama-3.3-70b | General purpose, reasoning |
| qwen3-coder | Code generation |
| deepseek-coder-v2 | Code + reasoning |
| qwen-2.5-72b | Multilingual, math |
| llama-3.1-8b | Fast, lightweight tasks |
Streaming
import OpenAI from 'ainative-openai';
const client = new OpenAI();
const stream = await client.chat.completions.create({
model: 'llama-3.3-70b',
messages: [{ role: 'user', content: 'Write a haiku about code.' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}Tool Calling
import OpenAI from 'ainative-openai';
const client = new OpenAI();
const response = await client.chat.completions.create({
model: 'qwen3-coder',
messages: [{ role: 'user', content: 'What is the weather in San Francisco?' }],
tools: [{
type: 'function',
function: {
name: 'get_weather',
description: 'Get current weather for a city',
parameters: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name' }
},
required: ['city']
}
}
}]
});
console.log(response.choices[0].message.tool_calls);Authentication
Credentials are resolved in this order:
opts.apiKeypassed to constructorAINATIVE_API_KEYenvironment variableOPENAI_API_KEYenvironment variableZERODB_API_KEYenvironment variable~/.ainative/config.json.mcp.jsonin project directory (walks up 6 levels)- Auto-provision a free account (credentials saved for next time)
Using an existing API key
export AINATIVE_API_KEY=ak_your_key_hereOr pass it directly:
const client = new OpenAI({ apiKey: 'ak_your_key_here' });Claiming your auto-provisioned account
On first run, you'll see a claim URL printed to stderr:
ainative-openai: No API key found — provisioning a free account...
Auto-provisioned! Project: proj_abc123
Claim your account: https://ainative.studio/claim/abc123Visit the claim URL to set a password and get persistent access.
Migrating from openai
- import OpenAI from 'openai';
+ import OpenAI from 'ainative-openai';
const client = new OpenAI();
- // Requires OPENAI_API_KEY and costs money
+ // Free Llama/Qwen/DeepSeek — auto-provisions if no key set
const res = await client.chat.completions.create({
- model: 'gpt-4',
+ model: 'llama-3.3-70b',
messages: [{ role: 'user', content: 'Hello!' }]
});Async Provisioning
If you need to ensure the API key is ready before making requests:
const client = new OpenAI();
await client.waitForProvisioning();
// Now safe to make requestsMCP Integration
After auto-provisioning, a .mcp.json entry is written so MCP-compatible tools (Claude Code, Cursor, Windsurf) can use your credentials:
{
"mcpServers": {
"ainative-openai": {
"command": "npx",
"args": ["-y", "ainative-openai"],
"env": {
"AINATIVE_API_KEY": "ak_...",
"AINATIVE_PROJECT_ID": "proj_..."
}
}
}
}License
MIT
