Prompt management
Prompt management keeps prompt templates out of application code. You store a prompt on the gateway, or in a prompt management system the gateway connects to, and applications send a prompt_id with variables instead of the full prompt. The gateway renders the template, applies the model and parameters the prompt defines, and calls the model. Changing a prompt then needs no deploy, every request log records which prompt produced it, and the people who write prompts can work in the Admin UI while engineers keep their code unchanged.
A real-world scenario
A support team's assistant greets customers and resolves one issue per conversation. The wording of the greeting and the tone of the replies change every few weeks as the team learns what works. Instead of shipping an application release each time, the team keeps the prompt on the gateway as support-reply. The application sends prompt_id: "support-reply" with the customer's name and the issue as variables. A content lead edits the prompt in the Prompt Studio, tests it in the built-in chat, saves a new version, and the next request uses it. When a change turns out worse, a request can pin the previous version while the lead fixes it.
Create a prompt and use it
-
Create the prompt. In the Admin UI open Prompts under AI Gateway and click Add New Prompt. The Prompt Studio opens. Pick the model, write the Developer message and the Prompt messages, using a variable name wrapped in double curly braces such as
{{customer_name}}, and click Save. The Publish Prompt dialog asks for a Name, which becomes the prompt id. Over the API, the prompt is sent in the dotprompt format, YAML front matter for the model and parameters followed by the template:curl -X POST http://localhost:4000/prompts \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"prompt_id": "support-reply","spanway_params": {"prompt_integration": "dotprompt","dotprompt_content": "---\nmodel: claude-sonnet-5-5\ntemperature: 0.3\n---\nYou are a support agent. Greet {{customer_name}} and resolve: {{issue}}."},"prompt_info": {"prompt_type": "db", "environment": "development"}}'Expected result: a
200with the stored prompt,version1 in thedevelopmentenvironment, and a row on the Prompts page. Proxy admins only. Sending the sameprompt_idagain adds the next version in that environment instead of failing. A prompt saved over the API is always stored withprompt_typedb, so it can be changed and deleted later, even when the body saysconfig. -
Use it from an application. The application sends the prompt id and the variables instead of the full prompt:
curl -X POST http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "claude-sonnet-5-5","prompt_id": "support-reply","prompt_variables": {"customer_name": "Jane", "issue": "double charge on order 4411"},"messages": [{"role": "user", "content": "I was charged twice"}]}'Expected result: a normal chat completion. The gateway rendered
You are a support agent. Greet Jane and resolve: double charge on order 4411., placed it before the message the application sent, and used the model and temperature from the prompt's front matter. Get Code on the prompt's detail page produces this call for curl, Python and JavaScript with the variables filled in. -
Check the log. Open Logs and click the request. The request's
metadata.prompt_management_metadatarecordsprompt_id,prompt_variablesandprompt_integration. The version and environment that were served are not recorded yet, so pinprompt_versionin the request when you need to compare versions. Treatprompt_variablesas request content, because it can carry customer names and similar data.
| Request field | Meaning |
|---|---|
prompt_id | The prompt to render. |
prompt_variables | Values for the template variables. |
prompt_version | A version number to pin, see prompt versions. Left out, the latest version is used. |
prompt_environment | The environment to read the prompt from, usually development, staging or production. Left out, the gateway serves production when the prompt has a production copy, otherwise staging, otherwise development. |
prompt_label | A label for integrations that select prompts by label. |
If the prompt defines its own model and parameters they are used, unless the prompt was registered with ignore_prompt_manager_model or ignore_prompt_manager_optional_params, both false by default.
A key or team can be limited to some prompts with its prompts field, a list of prompt ids, which needs a license that includes scoped_integrations. A request that names a prompt outside the key's list, or outside the team's list, is refused with 403 before anything is rendered. When both lists are set the prompt must be on both. A key or team with no prompts field may use every prompt.
A prompt_id the gateway does not know is not refused. The request is sent on as it is, without a stored template, so check the id when a reply ignores your prompt.
Where prompts can live
prompt_integration | Where prompts live |
|---|---|
dotprompt | Files or database entries in the dotprompt format. This is what the Prompts page creates. |
langfuse | A Langfuse prompt management project. |
gitlab, bitbucket | Prompt files in a source repository, read with an access token. |
arize_phoenix | Arize Phoenix prompts. |
generic_prompt_management | Your own HTTP service. |
custom | A Python class you provide. |
Remote integrations take api_base and api_key, and provider_specific_query_params passes extra parameters such as a label or version. An api_key saved over the API is stored encrypted with the gateway's salt key and every read route shows it masked, for example ****3456. Sending the masked value back in a PUT or PATCH keeps the stored key.
Prompts can also be declared in config.yaml, where each entry points at one .prompt file with prompt_file or holds the template inline in dotprompt_content:
prompts:
- prompt_id: support-reply
spanway_params:
prompt_integration: dotprompt
prompt_file: prompts/support-reply.prompt
Config file prompts show on the Prompts page with the type config and can only be changed in the file. A whole directory cannot be registered as one entry.
spanway_params key | Default | What it does |
|---|---|---|
prompt_integration | required | Where the template lives, from the table above. |
prompt_file | not set | Path to one .prompt file, config.yaml only. |
dotprompt_content | not set | The whole dotprompt template inline. |
prompt_id | the entry's prompt_id | The id the integration looks the template up by. |
ignore_prompt_manager_model | false | On, the request's own model wins over the prompt's model. |
ignore_prompt_manager_optional_params | false | On, the request's own parameters such as temperature win over the prompt's. |
api_base, api_key | not set | Address and key of a remote prompt service. |
provider_specific_query_params | not set | Extra query parameters for a remote prompt service. |
{{ops:^/prompts(/list|/{prompt_id}|/{prompt_id}/info)?$}}
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
403 {"error": "You are not authorized to access this prompt: support-reply. Your key's or team's prompts list does not include it"} | A model request with prompt_id | The key's or the team's prompts field leaves this prompt out. | Add the prompt to the key or team, or use another key. |
400 Prompt support-reply not found, ... not found in environment production | GET /prompts/{prompt_id}/info | No prompt has this id in the environment asked for, or the admin key's or its team's prompts list leaves it out. | Check the id on the Prompts page and the environment badge. |
403 You are not authorized to access this prompt. Your role - ... | GET /prompts/{prompt_id}/info | The key is not a proxy admin or admin viewer. | Use an admin key. |
400 spanway_params.prompt_id cannot be combined with prompt_data keyed by template name. ... | POST /prompts, PUT, PATCH | The body mixes two template shapes. | Send dotprompt_content, or a flat prompt_data with content and metadata. |
403 Only proxy admins can create prompts, Only proxy admins can update prompts, Only proxy admins can patch prompts, Only proxy admins can delete prompts | Each write route | The key is not a proxy admin. | Use an admin key. |
400 Cannot update config prompts. | PUT and PATCH /prompts/{prompt_id} | The prompt comes from the config file. | Change the file, or create a database prompt with another id. |
400 Cannot delete config prompts. | DELETE /prompts/{prompt_id} | The prompt comes from the config file. | Remove it from the file. |
404 Prompt with ID support-reply not found | PUT, DELETE | No version of the prompt is stored. | Create it with POST /prompts first. |
500 Failed to initialize prompt, Failed to update prompt, Failed to patch prompt | POST, PUT, PATCH | The template could not be loaded, for example a broken front matter block. | Fix the template and save again. |
500 Error converting prompt file: ... | POST /utils/dotprompt_json_converter | The uploaded .prompt file could not be read. | Check the file's front matter and encoding. |
500 DB not connected. ... | Any write | The gateway has no database. | Set DATABASE_URL, or use the config.yaml form. |
| The variables are rendered as empty text | A request with prompt_id | A variable name in prompt_variables does not match the template. | Compare the names with the Detected variables row under each message in the Prompt Studio. |
The error reference lists the same errors.
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | Error creating prompt: <error>, Error updating prompt: <error>, Error patching prompt: <error>, Error deleting prompt: <error> | A prompt write failed and the route answered 500. Nothing was saved. | Check the database and the template, then retry. |
| ERROR | Error testing prompt: <error> | The Prompt Studio test chat failed. | Check the prompt's model and its credentials. |
Every create, update, patch and delete also writes an audit row on Spanway_PromptTable with the version before and after. The template text is replaced by its SHA-256 and length and a remote api_key is masked, see audit logs.
Related
- Prompt versions and prompt tests for saving new versions, pinning one in a request, environments and the test chat.
- Prompts page for every control of the Admin UI page, including the Prompt Studio and the generated code dialog.
- Virtual keys for limiting a key to some prompts.
- Logging for the request log fields, including
prompt_management_metadata.