Skip to main content

Official Python SDK for InferexAI — OpenAI-compatible LLM gateway

Project description

inferexai

Official Python SDK for InferexAI — an OpenAI-compatible LLM gateway with prepaid billing, multi-provider fallback routing, and real-time usage analytics.

Installation

pip install inferexai

Quick start

from inferexai import InferexAI

client = InferexAI(api_key="sk-live-your-key-here")

response = client.chat.completions.create(
    model="my-chat-model",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

OpenAI-compatible

InferexAI extends openai.OpenAI — all existing methods work out of the box:

# Chat completions
response = client.chat.completions.create(model=..., messages=..., stream=True)

# Speech-to-Text
with open("audio.wav", "rb") as f:
    transcript = client.audio.transcriptions.create(model="whisper-stt", file=f)

# Text-to-Speech
audio = client.audio.speech.create(model="tts-voice", input="Hello!", voice="Karan")

# List models
models = client.models.list()

Streaming

stream = client.chat.completions.create(
    model="my-chat-model",
    messages=[{"role": "user", "content": "Tell me a story."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

InferexAI-specific features

Wallet

balance = client.wallet.balance()
print(f"Balance: ₹{balance['balance_inr']}")

API Keys

# List keys
keys = client.keys.list()

# Create a key
result = client.keys.create(
    name="production",
    expires_at="2027-01-01T00:00:00Z",
    scopes=["chat", "embeddings"],
)
print(result["key"])  # shown once — store securely

# Revoke a key
client.keys.revoke(key_id=42)

Usage

# List recent events
events = client.usage.list(from_date="2024-01-01", model="my-chat-model")

# Export as CSV
csv_data = client.usage.export(format="csv", from_date="2024-01-01")
with open("usage.csv", "w") as f:
    f.write(csv_data)

# Export as JSON
json_data = client.usage.export(format="json")

Organisation

# Get org
org = client.org.get()  # returns None if not in an org

# Create org
org = client.org.create("Acme Corp")

# Members
members = client.org.members.list()
client.org.members.invite(email="dev@acme.com", role="member")
client.org.members.remove(user_id=7)

Error handling

from inferexai import InferexAI, InferexAIError

try:
    response = client.chat.completions.create(model=..., messages=...)
except InferexAIError as e:
    print(e.status, str(e))  # e.g. 402 "insufficient wallet balance"

Configuration

client = InferexAI(
    api_key="sk-live-your-key-here",
    base_url="https://inferexapi.cloudvoice.in",  # default
)

Requirements

  • Python 3.8+
  • openai >= 1.0.0
  • httpx >= 0.24.0

Links

License

MIT © Enterux Solutions Pvt Ltd

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

inferexai-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

inferexai-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for inferexai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bce0c8dac0e720250bcfd88d9ed12dd480974a95fc2668bd6becca6e93faea6
MD5 c5e1ec47a5fbec47189941be4979de79
BLAKE2b-256 ff05b7584e9f49e542c77dcccd2d143b0b8515e3dfc7579e83fa4c6b136303f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: inferexai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for inferexai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6e1977a213a480d50be9ea60f8758177ac46862d0900c446b50de8e9a6e4c23
MD5 dafe6892755baca01f94876af6f5253f
BLAKE2b-256 32920f37090688f7973e10bc7217b856d3db536cd76373eebce9302df22e5f91

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