Skip to main content

Official Python SDK for PrimeLLM - Tool calling, streaming, multi-turn agents

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-1.0.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

primellm-1.0.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for primellm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d8f0e69f090ba7f209c7d9e8c25b2015c597d03a037235960209ddf0edfd5d76
MD5 ffcc0b9338d7b0d6c8d9beb803186b8a
BLAKE2b-256 c5c03f57adc60e63249459be8712f21ee0e8264719d809188e58874536749c6b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for primellm-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9dc45279e8fd9025d45e692069868834d322490099ee7c6f1bf82db7f9b69050
MD5 74eaffea5fe97b753cdaf0d4ea23946f
BLAKE2b-256 23c35dffb3337f388a42aaffb012e036dc279e07000bb99273f5231f248ba3a8

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