> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt Management

> Learn how to version your prompts, retrieve them programmatically, and keep them organized in PromptLayer.

It's easy to organize and version your prompts inside of PromptLayer. This guide explains how to save a new version and retrieve the latest one programmatically.

<Tip>
  This module requires an existing prompt in your PromptLayer account. Please
  follow the [Getting Started](/onboarding-guides/getting-started) guide to
  create one if needed.
</Tip>

## Update an Existing Prompt

Every time you update a prompt in PromptLayer, a new version is created. You will always be able to track changes, compare versions, or revert if needed.

### Example

In the [Getting Started Onboarding](/onboarding-guides/getting-started), we created a prompt called “ai-poet” to generate a haiku on a given topic. Initially, it uses a single input variable for the topic:

```
SYSTEM:
You are a skilled poet specializing in haikus.
Your task is to write a haiku based on a topic provided by the user.
The haiku must have 17 syllables, structured in three lines of 5, 7, and 5.

USER:
{topic}
```

Next, we will update the prompt to allow users to specify a language.

1. First, add a new input variable `{language}`
2. Update the system prompt to instruct the AI to consider both the topic and the language.

### Instructions

1. Navigate to the **Prompt Registry**.
2. Select the existing prompt you want to update (e.g., "ai-poet").
3. Click the **Edit Version #1** button to open the prompt in an editor.
4. Make some changes
5. Click **Update Template** to save these edits as a new version.
   <video controls>
     <source src="https://mintcdn.com/promptlayer/v0RzaTvbzopITX7U/onboarding-guides/videos/add-new-version.mp4?fit=max&auto=format&n=v0RzaTvbzopITX7U&q=85&s=6568712f046ae5964b71b265fa513e93" type="video/mp4" data-path="onboarding-guides/videos/add-new-version.mp4" />
   </video>

### Additional Features

* **Label** prompt versions for better organization (e.g., "prod" or "dev"). ([Learn more about release labels.](/features/prompt-registry/release-labels))
* Compare previous iterations to track improvements.
* Use **A/B testing** to evaluate performance differences. ([Learn more](/why-promptlayer/ab-releases))

***

## Retrieve Your Prompts from Code

To keep your PromptLayer prompts synchronized with your codebase, fetch the latest prompt version using the SDK.

1. Obtain an **API Key** by going to **Settings** → **PromptLayer API Keys**.
   <img src="https://mintcdn.com/promptlayer/v0RzaTvbzopITX7U/onboarding-guides/images/api-keys.png?fit=max&auto=format&n=v0RzaTvbzopITX7U&q=85&s=bd795f95e7207566cb40c4296ed11de1" alt="API Keys" width="1361" height="231" data-path="onboarding-guides/images/api-keys.png" />
2. Initialize the PromptLayer client in your application.

<CodeGroup>
  ```python Python theme={null}
  from promptlayer import PromptLayer

  pl_client = PromptLayer(api_key="YOUR_API_KEY")
  ```

  ```js Javascript theme={null}
  import { PromptLayer } from "promptlayer";

  const promptLayerClient = new PromptLayer({ apiKey: "YOUR_API_KEY" });
  ```
</CodeGroup>

3. Retrieve the prompt and run it. This will pull the latest prompt version, run it client side, and log the results.

<CodeGroup>
  ```python Python theme={null}
  response = pl_client.run(prompt_name="ai-poet")

  print(response)
  ```

  ```js Javascript theme={null}
  const response = await promptLayerClient.run({
    promptName: "ai-poet", 
    inputVariables: input_variables,
  });

  console.log(response);
  ```
</CodeGroup>

Once you’ve set up the SDK and your codebase is properly synced with PromptLayer:

* The latest or production version of your prompts will always synchronized.
* New prompt versions can be deployed without requiring engineering code deploys.

***

**Additional Resources:**

* Set up [Continuous Integration](/features/evaluations/continuous-integration#continuous-integration) using PromptLayer
* Learn more about the Prompt Registry [here](/features/prompt-registry/overview).
