Skip to main content

Drop-in replacement for the OpenAI Python SDK — routes to AINative's free Llama, Qwen, DeepSeek & Kimi API.

Project description

ainative-openai

Drop-in replacement for the OpenAI Python SDK that routes to AINative's free API — Llama, Qwen, DeepSeek, and Kimi models with zero configuration.

Install

pip install ainative-openai

Quick Start

Replace from openai import OpenAI with from ainative_openai import OpenAI. That's it.

from ainative_openai import OpenAI

client = OpenAI()  # auto-provisions a free API key

response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct",
    messages=[{"role": "user", "content": "Explain quantum computing in 3 sentences."}],
)
print(response.choices[0].message.content)

First run auto-provisions a free API key (72h expiry) and saves it to ~/.ainative/config.json. Follow the printed claim URL to get a permanent key.

Async

import asyncio
from ainative_openai import AsyncOpenAI

async def main():
    client = AsyncOpenAI()
    response = await client.chat.completions.create(
        model="qwen3-coder-flash",
        messages=[{"role": "user", "content": "Write a Python fibonacci generator"}],
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Streaming

from ainative_openai import OpenAI

client = OpenAI()
stream = client.chat.completions.create(
    model="deepseek-4-flash",
    messages=[{"role": "user", "content": "Write a haiku about code"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Tool Calling

from ainative_openai import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct",
    messages=[{"role": "user", "content": "What's the weather in Austin?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        },
    }],
)

Available Models

Model ID
Llama 3.3 70B meta-llama/Llama-3.3-70B-Instruct
Llama 4 Scout meta-llama/Llama-4-Scout-17B-16E-Instruct
Qwen3 Coder Flash qwen3-coder-flash
DeepSeek 4 Flash deepseek-4-flash
Kimi K2 kimi-k2

All models are free on AINative's API.

Authentication Priority

The client resolves API keys in this order:

  1. api_key argument
  2. AINATIVE_API_KEY environment variable
  3. OPENAI_API_KEY environment variable
  4. Saved key in ~/.ainative/config.json
  5. Auto-provision via instant-db (free, 72h expiry)

Configuration

# Explicit key
client = OpenAI(api_key="your-ainative-key")

# Custom base URL (self-hosted)
client = OpenAI(api_key="key", base_url="http://localhost:8000/v1")

# Environment variables
# AINATIVE_API_KEY=your-key
# AINATIVE_BASE_URL=https://custom.endpoint/v1

Migrating from OpenAI

- from openai import OpenAI
+ from ainative_openai import OpenAI

  client = OpenAI()
  response = client.chat.completions.create(
-     model="gpt-4",
+     model="meta-llama/Llama-3.3-70B-Instruct",
      messages=[{"role": "user", "content": "Hello!"}],
  )

Every feature of the official openai SDK works — this is a thin subclass that only changes the defaults.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ainative_openai-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ainative_openai-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file ainative_openai-0.1.0.tar.gz.

File metadata

  • Download URL: ainative_openai-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ainative_openai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6346e9025f62d98b325581c8c8466166b8583aa71a46ad535f8916833d1dac52
MD5 177b400162d64f33063482c963e0d8cb
BLAKE2b-256 1b39dbabb16fd7886268f127ce95946fb1dd64e1fecb9ab642ed25db7ee8d507

See more details on using hashes here.

File details

Details for the file ainative_openai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ainative_openai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0184265b9a60a595ef890c6adb54f20bb17c08122217d51c4b2c4a5af9a8d95a
MD5 2e12edc15ef2caf7865a2347fb6cbb59
BLAKE2b-256 ab04719ba0c84e5524ee75ef38ec3d881e7adb594d873f352e9f3118bdd0b0b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page