Python SDK
Installation
pip install promptlayer-hub
Requires Python 3.9+.
Client initialization
from promptlayer_hub import Client
client = Client(
api_key="your-key",
base_url="https://api.mlpipeline-cloud.com/v1", # optional
timeout=30, # seconds
)
Methods
client.run(prompt_name, variables=None)
Execute a prompt by name.
result = client.run(
prompt_name="support/greeting",
variables={"name": "Alice"},
)
print(result.response)
print(result.cost_usd)
print(result.latency_ms)
client.prompts.get(name)
Retrieve a prompt definition.
prompt = client.prompts.get("support/greeting")
print(prompt.template)
print(prompt.version)
client.prompts.create(name, template, model, parameters=None)
Create a new prompt.
client.prompts.update(name, template=None, parameters=None)
Update a prompt (creates new version).
client.evaluations.start(prompt_name, evaluator, rubric=None)
Start an evaluation run.
client.evaluations.get(evaluation_id)
Retrieve evaluation results.
Error handling
from promptlayer_hub import Client, APIError, RateLimitError
try:
result = client.run(prompt_name="missing")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except APIError as e:
print(f"API error: {e.code} — {e.message}")
Async client
from promptlayer_hub import AsyncClient
async def main():
client = AsyncClient(api_key="your-key")
result = await client.run("support/greeting", {"name": "Alice"})
print(result.response)