JavaScript
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 npm
.
Set up a PromptLayer client in your JavaScript file.
Optionally, you can specify the API key in the client.
OpenAI
In the JavaScript file where the OpenAI APIs are integrated, include the following lines. They enable PromptLayer to track your requests without additional code modifications.
You can then use openai
as you would if you had imported it directly.
Your OpenAI API Key is never sent to our servers. All OpenAI requests are made locally from your machine, PromptLayer just logs the request.
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!
Returning request id: return_pl_id
PromptLayer provides an option to retrieve the request id using the return_pl_id
argument. When set to true, it returns a tuple where the second element is the request id.
TypeScript
The PromptLayer JavaScript library also supports TypeScript. You can type cast the OpenAI
class to typeof BaseOpenAI
to get the correct typings.
You can also use our custom attributes pl_tags
and return_pl_id
with TypeScript. You will need to add the @ts-ignore
comment to ignore the TypeScript error.
This is because the pl_tags
and return_pl_id
arguments are not part of the OpenAI API.
Anthropic
Using Anthropic with PromptLayer is very similar to how to one would use OpenAI.
Below is an example code snippet of the one line replacement:
Here is how it would look like on the dashbaord:
Edge
PromptLayer can be used with Edge functions. Please use either our Javascript library or REST library directly.
Or use streaming. Here’s another example that can be run in NextJS on edge.