Skip to main content

PrimeLLM Python SDK

Official Python SDK for the PrimeLLM unified AI API.

Installation (Local Development)

cd py-sdk
pip install -e .

Quick Start

from primellm import PrimeLLM

# Create client with API key
client = PrimeLLM(api_key="primellm_live_XXXX")

# Or set PRIMELLM_API_KEY environment variable
# client = PrimeLLM()

# Make a chat request
resp = client.chat(
    model="gpt-5.1",
    messages=[{"role": "user", "content": "Hello!"}],
)

# Access the response
print(resp["choices"][0]["message"]["content"])
print(resp["usage"]["total_tokens"])
print(resp["credits"]["remaining"])

Available Models

Model Description
gpt-5.1 Latest GPT model
claude-sonnet-4.5 Claude Sonnet 4.5
gemini-3.0 Gemini 3.0

API Reference

PrimeLLM(api_key=None, base_url="https://api.primellm.in")

Create a new PrimeLLM client.

  • api_key: Your PrimeLLM API key. If not provided, reads from PRIMELLM_API_KEY env var.
  • base_url: API base URL (default: https://api.primellm.in)

client.chat(model, messages, **kwargs)

Send a chat completion request (OpenAI-compatible format).

Parameters:

  • model: Model name (e.g., "gpt-5.1")
  • messages: List of message dicts with role and content
  • **kwargs: Additional parameters like temperature, max_tokens

Returns: Dict with OpenAI-style response:

{
    "id": "chatcmpl_xxx",
    "model": "gpt-5.1",
    "choices": [
        {
            "message": {"role": "assistant", "content": "..."},
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 10,
        "completion_tokens": 20,
        "total_tokens": 30
    },
    "credits": {
        "cost": 0.00006,
        "remaining": 149.99
    }
}

client.generate(model, messages, **kwargs)

Legacy endpoint (for backwards compatibility).

Returns:

{
    "reply": "...",
    "model": "gpt-5.1",
    "tokens_used": 30,
    "cost": 0.00006,
    "credits_remaining": 149.99
}

Examples

With System Prompt

resp = client.chat(
    model="claude-sonnet-4.5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is Python?"},
    ],
)

With Temperature

resp = client.chat(
    model="gpt-5.1",
    messages=[{"role": "user", "content": "Write a poem"}],
    temperature=0.9,
)

Environment Variables

Variable Description
PRIMELLM_API_KEY Your PrimeLLM API key

License

MIT

Metadata

Release files for primellm 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for primellm 1.0.1
File Size Uploaded
primellm-1.0.1.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for primellm 1.0.1
File Interpreter ABI Platform
primellm-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / primellm-1.0.1.tar.gz

Download URL primellm-1.0.1.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d8f0e69f090ba7f209c7d9e8c25b2015c597d03a037235960209ddf0edfd5d76
BLAKE2b-256 checksum
How to use checksums
c5c03f57adc60e63249459be8712f21ee0e8264719d809188e58874536749c6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / primellm-1.0.1-py3-none-any.whl

Download URL primellm-1.0.1-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9dc45279e8fd9025d45e692069868834d322490099ee7c6f1bf82db7f9b69050
BLAKE2b-256 checksum
How to use checksums
23c35dffb3337f388a42aaffb012e036dc279e07000bb99273f5231f248ba3a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page