If you want to give Langtail a try but you’re not 100% sure that you want to use the full Langtail workflow, using the using the OpenAI Proxy via the SDK is a great way to get started. Follow these steps to get up and running:

1

Generate a project API key

  1. In Langtail, open an existing project or create a new one.
  2. In the left sidebar, click Secrets.
  3. Click New API Key, optionally set a name and a budget limit, then click Create.
  4. Copy the key.
2

Install the SDK

Install the Langtail SDK in your project (using NPM or your package manager of choice):

npm add langtail
3

Modify your code to use the SDK

  1. Add your Langtail project API key to an environment variable. In the following snippets, we use LANGTAIL_API_KEY.
  2. In your codebase, paste this snippet:
import { Langtail } from "langtail"

const lt = new Langtail({
  apiKey: process.env.LANGTAIL_API_KEY,
})

const rawCompletion = await lt.chat.completions.create({
  // Required
  messages: [{ role: "system", content: "You are a helpful assistant." }],
  model: "gpt-3.5-turbo",
  // Optional:
  // All OpenAI fields (temperature, top_p, tools,...)
  doNotRecord: false, // false will ensure logs do not contain any info about payloads
  metadata: {
    "custom-field": 1,
  },
})
4

Test it out

Run your app and make a request to verify that everything works properly.

5

Observe metrics and logs

  1. Back in Langtail, navigate to the project and then click Logs in the left sidebar.
  2. You should see log entries coming from your app (they have an environment value of “proxy”).
  3. Click on a log to see detailed information about the request and response from OpenAI.
  4. If you want to experiment with this prompt, click Open in Playground. Here you can change parameters and modify different parts of the prompt and then see the result.