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

# Prompts

> Prompt management and optimization at lytix

Lytix helps manage prompts directly in the CLI using our `lytix` cli commands.

<Info>
  **Note** We currently only support Typescript/Javascript.
</Info>

<Info>
  **🚨 Prerequisite** Login & setup your `lytix` CLI [here](/CLI/cli-login).
</Info>

# Sync your prompts (e.g. `git pull` your prompts)

Now you can sync your prompts to your local machine. This is the equivalent of `git pull` for your prompts.

If there are **changes that are uncommited or would cause a conflict**, you will be prompted to resolve them. You can pass the `--force` flag to skip this check and overwrite your local changes.

```bash
lytix prompt sync
```

<video controls className="w-full aspect-video" src="https://lytix-cdn.s3.amazonaws.com/documentationAssets/prompts/lytix-prompt-sync.mov" muted loop />

# Create a new prompt

Now let's create our first prompt. All you need to get started is a prompt name.

```bash
lytix prompt create --promptName "my new prompt"
```

<video controls className="w-full aspect-video" src="https://lytix-cdn.s3.amazonaws.com/documentationAssets/prompts/lytix-prompt-create.mov" muted loop />

# Edit & Use The Prompt

Now let's iterate on our prompt and start using it.

### Add Variables

Lytix supports adding templated variables to your prompts. This allows you to dynamically pass in variables when you use the prompt **and get type safety** as lytix will generate a `.ts` types file for you based on the inputs

Inside `prompt.json`, the `variables` field is where you can add your variables. It supports:

* `type`: `STRING` | `NUMBER` | `BOOLEAN` - The type of the variable
* `name`: The name of the variable

For example, a `prompt.json` file with a `toEcho` variable might look like this:

```json
{
    ...
    "variables": [
        {
      "type": "STRING",
      "name": "toEcho"
    }
  ]
}
```

### Update Prompts

After we've created the needed variables, we can update our system or user prompt by updating the `inputs.mdx` file:

```mdx
<UserPrompt>
  Please echo the following variable: ${{ toEcho }}
</UserPrompt>
<SystemPrompt>
  You are a helpful assistant.
</SystemPrompt>
```

### Commit Changes

Now you're ready to commit changes (e.g. `git commit && git push`).

<Note>
  **Note** This will **immediately** update the prompt and any incomming requests using the `promptId`
</Note>

```bash
lytix prompt commit
```

<video controls className="w-full aspect-video" src="https://lytix-cdn.s3.amazonaws.com/documentationAssets/prompts/lytix-prompt-commit.mov" muted loop />

### Pass `promptId` & Use Prompt

<Note>
  ⚠️ **Important** You need to use the `v2` baseURL: `https://api.lytix.co/proxy/v2/openai`. Please follow instructions [here](/Quickstart/openai-integration) to setup the lytix OpenAI integration.
</Note>

Now you are to use the `lytixPromptId` to start using your prompt. You can now pass an empty `messages` array and add the `lytixPromptId` & `lytixPromptVariables` to your request:

```ts
const client = new OpenAI({
  apiKey: LYTIX_API_KEY,
  baseURL: "https://api.lytix.co/proxy/v2/openai";,
  defaultHeaders: {
    anthropicApiKey: ANTHROPIC_API_KEY,
    openaiKey: OPENAI_API_KEY,
  },
});

/**
 * This is dyntamically generated type based on the prompt variables defined in `prompt.json`. 
 * Run `lytix prompt sync` to update them
 */
const inputVariables: my_new_promptInput = {
  toEcho: "This is coming from the lytix variable!",
};

const response = await client.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [],
    // @ts-expect-error lytix variables
    lytixPromptId: "464df7b9-81bf-435e-96ba-b95eab905452", // This promptId comes from the `prompt.json` file
    lytixPromptVariables: inputVariables,
});
```

<video controls className="w-full aspect-video" src="https://lytix-cdn.s3.amazonaws.com/documentationAssets/prompts/lytix-using-prompt.mov" autoPlay muted loop />

# Delete a prompt

Once you are ready to delete a prompt, you can do so with the following command:

```bash
lytix prompt delete --promptName "my new prompt"
```

<video controls className="w-full aspect-video" src="https://lytix-cdn.s3.amazonaws.com/documentationAssets/prompts/lytix-delete-prompt.mov" muted loop />
