Skip to main content

Official Python SDK for Promptlyzer - Multi-model routing layer for LLMs

Project description

Promptlyzer Python SDK

Official Python client for Promptlyzer - Multi-model routing layer for LLMs.

PyPI version Python 3.7+ License: MIT


What is Promptlyzer?

Promptlyzer is a production-ready LLM infrastructure layer that provides:

  • Smart model routing with complexity-based deployment strategies
  • Multi-provider support (OpenAI, Anthropic, Together AI, SiliconFlow)
  • Automatic cost optimization and credit management
  • Prompt management with versioning and caching
  • Real-time analytics and monitoring

Installation

pip install promptlyzer

# Upgrade to latest
pip install --upgrade promptlyzer

Requirements:

  • Python 3.7+
  • Promptlyzer API key

Quick Start

Step 1: Setup Your Account

  1. Sign up at promptlyzer.com
  2. Create a team (or use the default team created for you)
  3. Create a project to organize your deployments
  4. Get your API key from Settings → API Keys
  5. (Optional) Add your provider API keys at Providers page to use your own quota instead of credits

Step 2: Install and Initialize

pip install promptlyzer

# Set environment variable
export PROMPTLYZER_API_KEY="pk_live_YOUR_API_KEY"

Step 3: Create a Deployment

Why use deployments?

  • AI-powered smart routing across multiple model tiers
  • Automatic cost optimization based on request complexity
  • Real-time monitoring and analytics
  • No code changes needed when switching models

Create a deployment from your dashboard:

  1. Go to Deployments page in your project
  2. Click "Create Deployment"
  3. Configure your 3-tier routing:
    • Tier 1 (Fast & Cheap): e.g., gpt-4o-mini - Simple queries
    • Tier 2 (Balanced): e.g., gpt-4o - Standard requests
    • Tier 3 (Premium): e.g., claude-sonnet-4-5 - Complex tasks
  4. Copy your deployment ID

Smart Routing Engine:

  • Uses AI to analyze prompt complexity (0-100 score)
  • Considers task type and context length
  • Routes to optimal tier automatically

Step 4: Use Deployment for Inference

from promptlyzer import PromptlyzerClient

# Initialize client
client = PromptlyzerClient(api_key="pk_live_YOUR_API_KEY")

# Make inference request through deployment
response = client.deployments.infer(
    deployment_id="dep_abc123",
    prompt="Explain quantum computing in simple terms",
    task_type="customer_agent",  # Optional: helps routing decision
    context="Previous conversation..."  # Optional: chat history or documents
)

# Response contains
print(f"Response: {response['response']}")
print(f"Model: {response['model_used']}")
print(f"Tier: {response['tier']}")
print(f"Cost: ${response['cost_usd']:.6f}")
print(f"Latency: {response['latency_ms']}ms")

Smart Routing Logic (AI-Powered):

  • Analyzes prompt + context + task type
  • Calculates complexity score (0-100)
  • Routes to appropriate tier:
    • Tier 1 (0-40): Simple FAQ, quick responses
    • Tier 2 (40-70): Standard queries, moderate context
    • Tier 3 (70-100): Complex reasoning, large context

Using Your Own API Keys (No Credits):

response = client.deployments.infer(
    deployment_id="dep_abc123",
    prompt="Your prompt here",
    provider_api_key="sk-..."  # Your OpenAI/Anthropic key
)

View Deployment Logs

# Get all logs for a deployment
logs = client.deployments.get_logs(
    deployment_id="dep_abc123",
    status="success",  # or "error"
    limit=50
)

for log in logs:
    print(f"{log['timestamp']}: {log['model_id']} - ${log['cost_usd']:.6f}")

Alternative: Direct Inference (Without Deployment)

Use the same client for direct inference:

# Simple inference using credits (no deployment)
response = client.inference.infer(
    prompt="What is machine learning?",
    model="gpt-4o-mini"
)

print(response.content)
print(f"Cost: ${response.usage.cost_usd:.6f}")

One client, multiple features:

  • client.deployments.infer() → Smart routing with deployments
  • client.inference.infer() → Direct model inference
  • client.get_prompt() → Prompt management
  • client.billing.get_balance() → Credit management

Supported Models

OpenAI

  • gpt-5
  • gpt-4o (vision supported)
  • gpt-4o-mini
  • gpt-3.5-turbo

Anthropic

  • claude-3-5-sonnet-20241022 (vision supported)
  • claude-3-haiku-20240307
  • claude-3-opus-20240229

Together AI

Llama Models:

  • llama-3.3-70b-turbo
  • llama-3.3-70b-instruct-turbo
  • llama-3.1-8b-turbo
  • llama-3.2-3b
  • llama-4-scout (vision supported)
  • llama-4-maverick (vision supported)

Qwen Models:

  • qwen-2.5-72b
  • qwen-2.5-7b
  • qwen-qwq-32b
  • qwen3-235b

DeepSeek Models:

  • deepseek-v3
  • deepseek-v3.1
  • deepseek-r1-0528 (reasoning model)
  • deepseek-r1-distill-llama-70b
  • deepseek-r1-distill-qwen-14b
  • deepseek-r1-distill-qwen-1.5b

Other Models:

  • mixtral-8x7b
  • kimi-k2-instruct
  • openai-gpt-oss-120b
  • openai-gpt-oss-20b

SiliconFlow

Vision Models:

  • zai-org/GLM-4.5V
  • stepfun-ai/step3
  • THUDM/GLM-4.1V-9B-Thinking (thinking model)
  • Qwen/Qwen2.5-VL-72B-Instruct
  • Qwen/Qwen2.5-VL-32B-Instruct
  • Qwen/Qwen2.5-VL-7B-Instruct
  • deepseek-ai/deepseek-vl2

Text Models:

  • deepseek-ai/DeepSeek-V3.1
  • deepseek-ai/DeepSeek-R1 (reasoning model)
  • deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
  • zai-org/GLM-4.5
  • zai-org/GLM-4.5-Air
  • Qwen/Qwen3-235B-A22B-Instruct-2507
  • Qwen/Qwen3-235B-A22B-Thinking-2507 (thinking model)
  • moonshotai/Kimi-K2-Instruct
  • tencent/Hunyuan-A13B-Instruct
  • Qwen/QwQ-32B
  • Qwen/Qwen2.5-72B-Instruct
  • Qwen/Qwen2.5-32B-Instruct
  • Qwen/Qwen2.5-7B-Instruct
  • meta-llama/Meta-Llama-3.1-8B-Instruct

View pricing and details: Model Explorer


Authentication

Method 1: Environment Variable (Recommended)

export PROMPTLYZER_API_KEY="pk_live_your_api_key"
from promptlyzer import PromptlyzerClient
client = PromptlyzerClient()  # Auto-loads from environment

Method 2: Direct Initialization

client = PromptlyzerClient(api_key="pk_live_your_api_key")

Billing & Credits

Check Balance

balance = client.billing.get_balance()
print(f"Available: ${balance['available']:.2f}")
print(f"Used: ${balance['used']:.2f}")

Prompt Management

Get Prompt

prompt = client.get_prompt(
    project_id="proj_123",
    prompt_name="customer_support",
    environment="dev"  # or "staging", "prod"
)

print(prompt['content'])

Use Prompt in Inference

response = client.inference.infer(
    prompt=prompt['content'],
    model="claude-3-5-sonnet"
)

Prompts are cached for 5 minutes to reduce API calls.


Advanced Features

Streaming Responses

for chunk in client.inference.infer(
    prompt="Write a story",
    model="gpt-4o",
    stream=True
):
    print(chunk.content, end="", flush=True)

Error Handling

from promptlyzer.exceptions import (
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
    InferenceError
)

try:
    response = client.inference.infer(prompt, model)
except AuthenticationError:
    print("Invalid API key")
except InsufficientCreditsError as e:
    print(f"Out of credits: {e.available_credits}")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
except InferenceError as e:
    print(f"Inference failed: {e.message}")

Configuration

Unified Client

from promptlyzer import PromptlyzerClient

client = PromptlyzerClient(
    api_key="pk_live_YOUR_API_KEY",
    environment="dev"  # Options: "dev", "staging", "prod" (default: "dev")
)

One client for everything:

  • client.deployments.* → Deployment inference with smart routing
  • client.inference.* → Direct model inference
  • client.get_prompt() → Prompt management across environments
  • client.billing.* → Credit and usage management

Internal Settings (auto-configured):

  • Prompt cache TTL: 5 minutes
  • Connection pool size: 10
  • Request timeout: 10s (quick), 60s (inference)
  • Retry strategy: 3 attempts with exponential backoff

Documentation

Full documentation: DOCUMENTATION.md

Topics covered:

  • Deployment configuration and usage
  • Advanced inference options
  • Prompt management and versioning
  • Cost analytics and monitoring
  • Production best practices

Support


License

MIT License - See LICENSE for 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

promptlyzer-1.5.1.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

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

promptlyzer-1.5.1-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file promptlyzer-1.5.1.tar.gz.

File metadata

  • Download URL: promptlyzer-1.5.1.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for promptlyzer-1.5.1.tar.gz
Algorithm Hash digest
SHA256 95b08b3d9df924a2c91d1e28e82e3095254bd5a9fcd9ffeaf67ec29b68fcb7ee
MD5 40fa0babffd66d8aaf78087297066ddd
BLAKE2b-256 b9cd1ab5a3f5a671e6f2300ee32c68937335a8e586bf8f6e956570da8a5f83ce

See more details on using hashes here.

File details

Details for the file promptlyzer-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: promptlyzer-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for promptlyzer-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14ea4aea2f907bf9bf2be9f788d9dbc4671ba45a877d3ab099567d22e5e24890
MD5 75990edf89b4e36caf1583e7f07b2f9f
BLAKE2b-256 69a962edb31444f254cf39dcdb7b416cb302076e58f53f6277ab2cd459e2476b

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