Skip to main content

LLM inference SDK, for telemetry and internal model routing

Project description

Maniac Python SDK

The official Python client for the Maniac Inference Gateway API — an OpenAI-compatible inference gateway with telemetry, containers, evaluation, and optimization.

Installation

pip install maniac

Quick Start

from maniac import Maniac

client = Maniac()  # uses MANIAC_API_KEY env var

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(completion["choices"][0]["message"]["content"])

Chat Completions

Create a completion

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
maniac chat completions create \
  --model openai/gpt-4o \
  --messages '[{"role": "user", "content": "What is the capital of France?"}]'

Stream a completion

for chunk in client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku."}],
    stream=True,
):
    print(chunk, end="", flush=True)
maniac chat completions create \
  --model openai/gpt-4o \
  --messages '[{"role": "user", "content": "Write a haiku."}]' \
  --stream

List completions

completions = client.chat.completions.list(limit=10, container="my-container")
maniac chat completions list --limit 10 --container my-container

Retrieve a completion

completion = client.chat.completions.retrieve("completion-id")
maniac chat completions retrieve completion-id

Register examples

client.chat.completions.register(
    container="my-container",
    items=[
        {
            "input": {
                "model": "openai/gpt-4o",
                "messages": [{"role": "user", "content": "Hi"}],
            },
            "output": {
                "choices": [{"message": {"role": "assistant", "content": "Hello!"}}],
            },
        }
    ],
)
maniac chat completions register \
  --container my-container \
  --items '[{"input": {"model": "openai/gpt-4o", "messages": [{"role": "user", "content": "Hi"}]}, "output": {"choices": [{"message": {"role": "assistant", "content": "Hello!"}}]}}]'

Containers

Create a container

container = client.containers.create(
    label="my-container",
    initial_model="openai/gpt-4o",
)
maniac containers create --label my-container --initial-model openai/gpt-4o

List containers

containers = client.containers.list()
maniac containers list

Retrieve a container

container = client.containers.retrieve("my-container")
maniac containers retrieve my-container

Delete a container

client.containers.delete("my-container")
maniac containers delete my-container

Models

List models

models = client.models.list()
maniac models list

Add a model to a container

client.models.add(
    container="my-container",
    model="anthropic/claude-sonnet-4.5",
    slug="claude",
)
maniac models add \
  --container my-container \
  --model anthropic/claude-sonnet-4.5 \
  --slug claude

Files

Upload a file

file = client.files.create(file="data.jsonl", purpose="fine-tune")
maniac files create data.jsonl --purpose fine-tune

List files

files = client.files.list()
maniac files list

Retrieve file metadata

file = client.files.retrieve("file-id")
maniac files retrieve file-id

Download file content

content = client.files.content("file-id")
maniac files content file-id

Delete a file

client.files.delete("file-id")
maniac files delete file-id

Evaluators

Create an evaluator

evaluator = client.evaluators.create(
    type="judge",
    model="openai/gpt-4o",
    name="quality-judge",
    prompt="Rate the quality of the response from 1-10.",
    container="my-container",
)
maniac evaluators create \
  --type judge \
  --model openai/gpt-4o \
  --name quality-judge \
  --prompt "Rate the quality of the response from 1-10." \
  --container my-container

List evaluators

evaluators = client.evaluators.list(container="my-container")
maniac evaluators list --container my-container

Retrieve an evaluator

evaluator = client.evaluators.retrieve("evaluator-id")
maniac evaluators retrieve evaluator-id

Update an evaluator

client.evaluators.update("evaluator-id", prompt="New prompt text.")
maniac evaluators update evaluator-id --prompt "New prompt text."

Delete an evaluator

client.evaluators.delete("evaluator-id")
maniac evaluators delete evaluator-id

Evaluation Runs

Create an evaluation run

run = client.evaluation.runs.create(
    container="my-container",
    evaluators=["evaluator-id"],
)
maniac evaluation runs create \
  --container my-container \
  --evaluators '["evaluator-id"]'

List evaluation runs

runs = client.evaluation.runs.list(container="my-container")
maniac evaluation runs list --container my-container

Retrieve an evaluation run

run = client.evaluation.runs.retrieve("run-id")
maniac evaluation runs retrieve run-id

Datasets

Create a dataset

dataset = client.datasets.create(
    name="my-dataset",
    container="my-container",
    size=100,
)
maniac datasets create \
  --name my-dataset \
  --container my-container \
  --size 100

List datasets

datasets = client.datasets.list(container="my-container")
maniac datasets list --container my-container

Retrieve a dataset

dataset = client.datasets.retrieve("dataset-id")
maniac datasets retrieve dataset-id

Optimization Runs

Create an optimization run

run = client.optimization.runs.create(
    container="my-container",
    base_models=["openai/gpt-4o"],
    evals=["evaluator-id"],
    methods=[{"type": "sft"}],
)
maniac optimization runs create \
  --container my-container \
  --base-models '["openai/gpt-4o"]' \
  --evals '["evaluator-id"]' \
  --methods '[{"type": "sft"}]'

OpenAI Compatibility

Maniac's inference endpoint is fully compatible with the OpenAI client. Point it at https://platform.maniac.ai/api/v1 and prefix your container label with maniac::

from openai import OpenAI

client = OpenAI(
    base_url="https://platform.maniac.ai/api/v1",
    api_key=os.getenv("MANIAC_API_KEY"),
)

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

Async Usage

from maniac import AsyncManiac

async def main():
    async with AsyncManiac() as client:
        completion = await client.chat.completions.create(
            model="openai/gpt-4o",
            messages=[{"role": "user", "content": "Hello!"}],
        )
        print(completion["choices"][0]["message"]["content"])

        # Streaming
        async for chunk in await client.chat.completions.create(
            model="openai/gpt-4o",
            messages=[{"role": "user", "content": "Write a poem."}],
            stream=True,
        ):
            print(chunk, end="", flush=True)

Error Handling

from maniac import Maniac, AuthenticationError, RateLimitError, NotFoundError

client = Maniac()

try:
    client.containers.retrieve("nonexistent")
except NotFoundError:
    print("Container not found")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")

All exceptions inherit from ManiacError. The full hierarchy:

  • ManiacError
    • APIError — generic API error (has status_code and code)
    • AuthenticationError — 401/403
    • RateLimitError — 429 (has retry_after)
    • NotFoundError — 404
    • BadRequestError — 400/422
    • APIConnectionError — network failure

CLI Global Options

Every command supports --json for raw JSON output and --api-key / --base-url overrides:

maniac --api-key sk-... containers list --json

Run maniac --help or maniac <command> --help for full option details.

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

maniac-0.5.2.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

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

maniac-0.5.2-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file maniac-0.5.2.tar.gz.

File metadata

  • Download URL: maniac-0.5.2.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for maniac-0.5.2.tar.gz
Algorithm Hash digest
SHA256 16883a80b32421dbd6d165148c667acd35c71dd05c6c3643a732849a5eb3a411
MD5 58e69b2216e87ee5d2006cd9d241deb3
BLAKE2b-256 5cc70f2f00818c74e232cd7a9ad661accd8ed23b4b0eb7c0daad9ad21dd1e3d5

See more details on using hashes here.

File details

Details for the file maniac-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: maniac-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for maniac-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64355859cb46a774f8f0bc233ec2d3324c44cad41485ced38f3ba0e7a8015c5b
MD5 ccd2128d26a9ab549952ea35db99a005
BLAKE2b-256 1f98c6666f19e82342d9d2698939b059c72729c43ab89d4b156c3d66d07ad41e

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