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.
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
- Sign up at promptlyzer.com
- Create a team (or use the default team created for you)
- Create a project to organize your deployments
- Get your API key from Settings → API Keys
- (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:
- Go to Deployments page in your project
- Click "Create Deployment"
- 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
- 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 deploymentsclient.inference.infer()→ Direct model inferenceclient.get_prompt()→ Prompt managementclient.billing.get_balance()→ Credit management
Supported Models
OpenAI
gpt-5gpt-4o(vision supported)gpt-4o-minigpt-3.5-turbo
Anthropic
claude-3-5-sonnet-20241022(vision supported)claude-3-haiku-20240307claude-3-opus-20240229
Together AI
Llama Models:
llama-3.3-70b-turbollama-3.3-70b-instruct-turbollama-3.1-8b-turbollama-3.2-3bllama-4-scout(vision supported)llama-4-maverick(vision supported)
Qwen Models:
qwen-2.5-72bqwen-2.5-7bqwen-qwq-32bqwen3-235b
DeepSeek Models:
deepseek-v3deepseek-v3.1deepseek-r1-0528(reasoning model)deepseek-r1-distill-llama-70bdeepseek-r1-distill-qwen-14bdeepseek-r1-distill-qwen-1.5b
Other Models:
mixtral-8x7bkimi-k2-instructopenai-gpt-oss-120bopenai-gpt-oss-20b
SiliconFlow
Vision Models:
zai-org/GLM-4.5Vstepfun-ai/step3THUDM/GLM-4.1V-9B-Thinking(thinking model)Qwen/Qwen2.5-VL-72B-InstructQwen/Qwen2.5-VL-32B-InstructQwen/Qwen2.5-VL-7B-Instructdeepseek-ai/deepseek-vl2
Text Models:
deepseek-ai/DeepSeek-V3.1deepseek-ai/DeepSeek-R1(reasoning model)deepseek-ai/DeepSeek-R1-Distill-Qwen-32Bzai-org/GLM-4.5zai-org/GLM-4.5-AirQwen/Qwen3-235B-A22B-Instruct-2507Qwen/Qwen3-235B-A22B-Thinking-2507(thinking model)moonshotai/Kimi-K2-Instructtencent/Hunyuan-A13B-InstructQwen/QwQ-32BQwen/Qwen2.5-72B-InstructQwen/Qwen2.5-32B-InstructQwen/Qwen2.5-7B-Instructmeta-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 routingclient.inference.*→ Direct model inferenceclient.get_prompt()→ Prompt management across environmentsclient.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
- Documentation: docs.promptlyzer.com
- Dashboard: promptlyzer.com
- Email: contact@promptlyzer.com
License
MIT License - See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95b08b3d9df924a2c91d1e28e82e3095254bd5a9fcd9ffeaf67ec29b68fcb7ee
|
|
| MD5 |
40fa0babffd66d8aaf78087297066ddd
|
|
| BLAKE2b-256 |
b9cd1ab5a3f5a671e6f2300ee32c68937335a8e586bf8f6e956570da8a5f83ce
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14ea4aea2f907bf9bf2be9f788d9dbc4671ba45a877d3ab099567d22e5e24890
|
|
| MD5 |
75990edf89b4e36caf1583e7f07b2f9f
|
|
| BLAKE2b-256 |
69a962edb31444f254cf39dcdb7b416cb302076e58f53f6277ab2cd459e2476b
|