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.

pip install promptlayer

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.

import 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.

<aside> 💡 Your OpenAI API Key is never sent to our servers. All OpenAI requests are made locally from your machine, PromptLayer just logs the request.

</aside>

There is only one difference… 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!

Screen Shot 2022-12-30 at 6.16.08 PM.png

Here is a complete code snippet:

import promptlayer
import os
promptlayer.api_key = os.environ.get("PROMPTLAYER_API_KEY")
openai=promptlayer.openai
openai.api_key = os.environ.get("OPENAI_API_KEY")
openai.Completion.create(
					engine="text-ada-001", 
					prompt="My name is", 
					pl_tags=["name-guessing", "pipeline-2"]
)