Skip to main content

PromptLayer is a platform for prompt engineering and tracks your LLM requests.

Project description

🍰 PromptLayer

The first platform built for prompt engineers

Python Docs Demo with Loom


PromptLayer is the first platform that allows you to track, manage, and share your GPT prompt engineering. PromptLayer acts a middleware between your code and OpenAI’s python library.

PromptLayer records all your OpenAI API requests, allowing you to search and explore request history in the PromptLayer dashboard.

This repo contains the Python wrapper library for PromptLayer.

Quickstart ⚡

Install PromptLayer

pip install promptlayer

Installing PromptLayer Locally

Use pip install . to install locally.

Claude Agents Integration

PromptLayer also ships an optional Claude Agents integration that exposes a vendored PromptLayer Claude plugin configuration.

This integration currently supports Linux and macOS. Windows is not supported.

pip install "promptlayer[claude-agents]"
from claude_agent_sdk import ClaudeAgentOptions
from promptlayer.integrations.claude_agents import get_claude_config

pl_claude_config = get_claude_config()

options = ClaudeAgentOptions(
  model="sonnet",
  cwd=".",
  plugins=[pl_claude_config.plugin],
  env={**pl_claude_config.env},
)

Using PromptLayer

To get started, create an account by clicking “Log in” on PromptLayer. Once logged in, click the button to create an API key and save this in a secure location (Guide to Using Env Vars).

Once you have that all set up, install PromptLayer using pip.

In the Python file where you use OpenAI APIs, add the following. This allows us to keep track of your requests without needing any other code changes.

from promptlayer import PromptLayer

promptlayer = PromptLayer(api_key="<YOUR PromptLayer API KEY pl_xxxxxx>")
openai = promptlayer.openai

You can then use openai as you would if you had imported it directly.

Adding PromptLayer tags: pl_tags

PromptLayer allows you to add tags through the pl_tags argument. This allows you to track and group requests in the dashboard.

Tags are not required but we recommend them!

openai.Completion.create(
  engine="text-ada-001",
  prompt="My name is",
  pl_tags=["name-guessing", "pipeline-2"]
)

After making your first few requests, you should be able to see them in the PromptLayer dashboard!

Using the REST API

This Python library is a wrapper over PromptLayer's REST API. If you use another language, like Javascript, just interact directly with the API.

Here is an example request below:

import requests
request_response = requests.post(
  "https://api.promptlayer.com/track-request",
  json={
    "function_name": "openai.Completion.create",
    "args": [],
    "kwargs": {"engine": "text-ada-001", "prompt": "My name is"},
    "tags": ["hello", "world"],
    "request_response": {"id": "cmpl-6TEeJCRVlqQSQqhD8CYKd1HdCcFxM", "object": "text_completion", "created": 1672425843, "model": "text-ada-001", "choices": [{"text": " advocacy\"\n\nMy name is advocacy.", "index": 0, "logprobs": None, "finish_reason": "stop"}]},
    "request_start_time": 1673987077.463504,
    "request_end_time": 1673987077.463504,
    "api_key": "pl_<YOUR API KEY>",
  },
)

Contributing

We welcome contributions to our open source project, including new features, infrastructure improvements, and better documentation. For more information or any questions, contact us at hello@promptlayer.com.

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

promptlayer-1.4.1.tar.gz (75.0 kB view details)

Uploaded Source

Built Distribution

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

promptlayer-1.4.1-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file promptlayer-1.4.1.tar.gz.

File metadata

  • Download URL: promptlayer-1.4.1.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-1010-azure

File hashes

Hashes for promptlayer-1.4.1.tar.gz
Algorithm Hash digest
SHA256 bb16b21c1b9e4bd6555512857a69fef2c658e313fd9a93d83a76d31d87f53a5d
MD5 e2448ebe24c580b74985f9bc9f000043
BLAKE2b-256 3b0a1186af1048098d9acc2fda8ea4eb20c9b74a14018478cba63031a652350d

See more details on using hashes here.

File details

Details for the file promptlayer-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: promptlayer-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-1010-azure

File hashes

Hashes for promptlayer-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f28abc94d33808eefe11f9f899ea0ac95cb241f5d151d1f6dd55f024af05d659
MD5 49910290df55d5d5e441ad903df765d1
BLAKE2b-256 c4f8d1ce9c7e3e162a50fb517a391c718373cdba24ca9b803edd9ca8afb625f7

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