Skip to main content

Official Python client for the PrimeLLM unified AI API

Project description

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

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

primellm-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

primellm-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for primellm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75a16cbbecd0aff95a4e249875b97baebe5c4a9a1e474c6614315dd900125327
MD5 eefacb8f43eb8f93e9587567816b2096
BLAKE2b-256 e4739effc0c0691baea8e36d8a5cf567f9d4d213198a48484f5dd9142c1b3b7c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for primellm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 805b4598d448760e5bacafff01c887ca42e3380d6dbc9ffa25bce2959b8b5a42
MD5 bf67be642c86d3cca21d466d5f060a2f
BLAKE2b-256 aa718d0ef41cf183745da8ea895407284f74bbf149cb6f48597f840454927c13

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