Opik provides a prompt library that you can use to manage your prompts. Storing prompts in a library allows you to version them, reuse them across projects, and manage them in a central location.
In Opik 2.0, prompts are project-scoped. Specify a project_name when creating prompts to associate them with the correct project.
Using a prompt library does not mean you can’t store your prompt in code, we have designed the prompt library to work seamlessly with your existing prompt files while providing the benefits of a central prompt library.
Opik supports two types of prompts:
Text prompts are simple string-based templates that support variable substitution. They are ideal for single-turn interactions or when you need to generate a single piece of text.
The recommended way to create and manage text prompts is using the
Prompt
object. This will allow you to continue versioning your prompts in code while
also getting the benefit of having prompt versions managed in the Opik platform
so you can more easily keep track of your progress.
Prompts can also be stored in a file and loaded from it:
The prompt will now be stored in the library and versioned:

The Prompt
object will create a new prompt in the library if this prompt doesn’t already exist,
otherwise it will return the existing prompt.
This means you can safely run the above code multiple times without creating duplicate prompts.
If you would rather keep text prompts in the Opik platform and manually update / download them, you can use the low-level Python SDK to manage your prompts.
When to use client methods vs. classes:
Use Prompt() class (recommended): For most use cases, this class automatically uses the global Opik configuration set by opik.configure().
Use client.create_prompt(): When you need to use a specific client configuration that differs from the global configuration (e.g., different workspace, host, or API key).
You can create a new prompt in the library using both the SDK and the UI:
You can associate prompts with your traces and spans using the opik_context module. This is useful when you want to track which prompts were used during the execution of your functions:
You can view the prompts associated with a trace or span in the Opik UI:

Further details on using prompts from the Prompt library are provided in the following sections.
Prompts can be used in all supported third-party integrations by attaching them to traces and spans through the opik_context module.
For instance, you can use prompts with the Google ADK integration, as shown in the example here.
Once a prompt is created in the library, you can download it in code:
Use the Opik.get_prompt method:
If you are not using the SDK, you can download a prompt by using the REST API.
To discover prompts by name substring and/or filters, use search_prompts. Filters are written in Opik Query Language (OQL):
Use search_prompts:
You can filter by template_structure to search for only text prompts ("text") or only chat prompts ("chat"). Without the filter, search_prompts returns both types.
The filter_string parameter uses Opik Query Language (OQL) with the format:
"<COLUMN> <OPERATOR> <VALUE> [AND <COLUMN> <OPERATOR> <VALUE>]*"
Supported columns for prompts:
Examples:
tags contains "production" - Filter by tagname contains "summary" - Filter by name substringcreated_by = "user@example.com" - Filter by creatortags contains "alpha" AND tags contains "beta" - Multiple tag filteringtemplate_structure = "text" - Filter for only text promptstemplate_structure = "chat" - Filter for only chat promptssearch_prompts returns the latest version for each matching prompt.
Chat prompts are structured message-based templates designed for conversational AI applications. They support multiple message roles (system, user, assistant) and multimodal content including text, images, and videos.
{{variable}}) or Jinja2 syntaxSimilar to text prompts, you can create and manage chat prompts using the
ChatPrompt
class. This allows you to version your chat prompts in code while benefiting from
centralized management in the Opik platform.
Chat prompts work seamlessly with OpenAI’s chat completion API:
You can create templates for multi-turn conversations:
The chat prompt will now be stored in the library and versioned, just like text prompts.
The ChatPrompt
class will create a new chat prompt in the library if it doesn’t already exist,
otherwise it will return the existing prompt.
This means you can safely run the code multiple times without creating duplicate prompts.
Once created, you can view and manage your chat prompts in the Opik UI:

Chat prompts support multimodal content, allowing you to include images and videos alongside text. This is useful for vision-enabled models.
Chat prompts can also include video content:
You can combine multiple types of content in a single message:
When formatting multimodal prompts, you can specify supported_modalities to control how content is rendered:
{"vision": True}), the structured content is preserved<<<image>>><<</image>>>)This allows you to use the same prompt template with different models that may or may not support certain modalities.
You can also use the low-level Python SDK to create and manage chat prompts directly.
When to use client methods vs. classes:
Use ChatPrompt() or Prompt() classes (recommended): For most use cases, these classes automatically use the global Opik configuration set by opik.configure().
Use client.create_chat_prompt() or client.create_prompt(): When you need to use a specific client configuration that differs from the global configuration (e.g., different workspace, host, or API key).
Use Opik.create_chat_prompt to create a chat prompt:
Once a chat prompt is created in the library, you can download it in code:
Use the Opik.get_chat_prompt method:
You can search for chat prompts specifically by using the template_structure filter:
Use Opik.search_prompts with the filter:
To search for text prompts only, use template_structure = "text". Without the filter, search_prompts returns both text and chat prompts.
The filter_string parameter uses Opik Query Language (OQL) and supports the same columns and operators as text prompts (see Searching prompts above).
Chat prompts support two template types for variable substitution.
For more advanced templating with conditionals, loops, and filters:
Jinja2 templates support advanced features like conditionals, loops, and filters, making them more powerful for complex prompt logic. However, Mustache templates are simpler and more portable.
Chat prompts are automatically versioned when the messages change. Each version has a unique commit ID.
You can use get_chat_prompt to retrieve a specific version by commit ID, and get_chat_prompt_history to get all versions.
If you create a chat prompt with identical messages to an existing version, Opik will return the existing version instead of creating a duplicate. This helps avoid unnecessary version proliferation.
Once you create a prompt with a specific structure (text or chat), that structure cannot be changed. This ensures consistency and prevents accidental mixing of prompt types.
Similarly, if you create a text prompt first, you cannot later create a chat prompt with the same name.
Both Prompt and ChatPrompt classes will raise a PromptTemplateStructureMismatch exception if you attempt to change the structure of an existing prompt.
Use get_prompt_history for text prompts:
This returns a list of Prompt objects (each representing a specific version) for the given prompt name.
You can use this information to:
Use the commit parameter with get_prompt:
The commit parameter accepts the commit ID of the specific prompt version you want to retrieve. You can find commit IDs in the prompt history in the Opik UI or by using the get_prompt_history or get_chat_prompt_history methods (see above).
This is particularly useful when you want to:
Opik supports tags at two levels, which serve different purposes:
tags parameter when creating or updating a prompt. These are used for searching and organizing prompts and are covered in the Searching prompts section.batch_update_prompt_version_tags / updatePromptVersionTags API after creating the version. These allow you to label individual milestones (e.g., “production”, “stable”, “deprecated”) and filter version history.This section covers prompt version tags (the per-version ones).
When you open a prompt from the library, the prompt page shows its full commit history — each version listed as a row with its commit ID, creation date, and any tags assigned to it:

The commits table gives you a detailed view of all versions for a prompt. Each row shows the commit ID, template preview, change description, author, creation date, and the tags attached to that version. You can add or remove tags directly from this table by clicking on the tag editor for any row:

The commits table supports filtering so you can quickly find versions by tag, template content, author, or other fields. Use the filter controls above the table to apply one or more filters:

When selecting a version to compare, the dropdown lists all versions with their tags displayed inline, making it easy to identify the right candidate without opening each version individually:

Once two versions are selected, their tags are shown alongside the commit ID and change description in the comparison dialog:

Use the batch update API to efficiently update tags on one or more prompt versions at once. This is especially useful when you want to promote a version to production or clean up tags after a release.
There are two update modes:
Access the PromptClient from the Opik client via get_prompts_client(), then call batch_update_prompt_version_tags:
You can search, filter, and sort prompt version history to find specific versions.
search performs a free-text match against template content and change description fields:
Use filter_string (Python OQL) or filters (TypeScript JSON array) to narrow results by any version field.
Supported fields for version filtering:
For Python, conditions are combined with AND in the OQL string. For TypeScript, add multiple objects to the filter array.
Sorting is currently only supported in the TypeScript SDK. Python’s get_prompt_history and get_chat_prompt_history always return versions newest-first.
Use the sorting option with a JSON-encoded sort array. Each entry specifies a field and direction ("ASC" or "DESC"):
Sortable fields include: id, commit, template, change_description, created_by, type, created_at.
The following end-to-end example shows a common workflow: create a new prompt version, and then promote the best-performing version by tagging it as production.
The experiment will now be linked to the prompt, allowing you to view all experiments that use a specific prompt:

This workflow allows you to systematically test and compare different prompt versions to identify the most effective one for your use case.