Skip to main content

Official Python SDK for Promptly - LLM cost optimization proxy

Project description

promptly-ai

Official Python SDK for Promptly - LLM cost optimization proxy.

Install

pip install promptly-ai

Quick Start

from promptly import Promptly

client = Promptly(api_key="sk-promptly-...")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a poem."}],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Access Promptly Metadata

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

meta = response.promptly_metadata
print(f"Saved: ${meta['savings']}")
print(f"Routed to: {meta['routed_model']}")
print(f"Cache hit: {meta['cache_hit']}")

Wrap Existing Client

Already using the OpenAI SDK? Wrap it in one line:

import openai
from promptly import wrap

client = wrap(openai.OpenAI(api_key="sk-your-openai-key"))
# All calls now go through Promptly

Configuration

client = Promptly(
    api_key="sk-promptly-...",
    base_url="https://api.getpromptly.in/v1",  # default
    timeout=30,                                  # seconds
    max_retries=2,                               # auto-retry on failure
)

Requirements

  • Python 3.8+
  • openai >= 1.0.0

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

promptly_sdk-0.1.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

promptly_sdk-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file promptly_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: promptly_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for promptly_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ae2251c26c3c6efefe3266e6cf8fac7c9bc50e19d6d61a16a2130fe732c621cd
MD5 1a4557caca71d594f445fc7a0dee3f1e
BLAKE2b-256 13e7c6aa12ec5519de4dcf89716b82dfb82a43fd955bd4a1b00c771ea663d6d9

See more details on using hashes here.

File details

Details for the file promptly_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: promptly_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for promptly_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e84d01f3b6848cc5301c267b5cc442972d68cd785ad068abf439b4469b793d1f
MD5 3a206c782aa3be1389037f22a5be0a6b
BLAKE2b-256 f35fdc95d41dfff75d13cedb15ad9faba32f604cd60a59a964f26af08cfe0000

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