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.2.0.tar.gz (9.2 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.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for primellm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 958c367d1687bb251bf5d49fbad15eeaa8c4ac4994be7c4908d31bcdb948cc87
MD5 6a67d2a5471e994fe64b799018643c36
BLAKE2b-256 5ad176d548f2c1109f274cb0e88f5f922dd7185579eb4dfba0baa62d47dafffa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: primellm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 362605b6e6fead6766855eed58bfb9f91d46a3ef0768a491bc715e0e3de95e2c
MD5 5b6a2db29a115e22a7950feb21ad0ca5
BLAKE2b-256 9f77e4fcb2d098637494da28011ca967930c7f3b67ed7a90e4402be2d6eb0e30

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