Skip to main content

Prompt versions and prompt tests

Every prompt stored on the Spanway gateway is versioned per environment, usually development, staging and production. Saving a change through the Prompt Studio, PUT or PATCH never overwrites anything: it adds the next version in the chosen environment, the latest version is what requests get by default, and older versions stay available for a request to pin. Before a version is saved it can be tried against a real model with sample variables. This page is for the people who iterate on prompts and the engineers who need to know which version their application is talking to.

A real-world scenario​

A content lead is improving the support-reply prompt. She opens it in the Prompt Studio, changes the greeting, fills the variables in the test chat and reads the model's reply, then saves version 3 in development. The staging application already points at development with prompt_environment, so the team tries it for a day. The next day she promotes it into production with the eval run that tested it, it becomes production version 2, and the customer facing application picks it up on its next request. A week later a complaint comes in, and an engineer pins prompt_version: 1 in production for that one integration while the lead prepares version 3.

Save a new version​

  1. Open the prompt. In the Admin UI open Prompts under AI Gateway, click the prompt id, and click Prompt Studio. The header shows the version you loaded as a badge such as v2 and the environment selector.

  2. Change it and test it. Edit the Developer message or the Prompt messages. In the test chat on the right, fill in each variable the prompt uses, type a message and press Enter. The reply streams in with the model name, latency and token usage. This is a real model call and costs money. Over the API the test takes the dotprompt text and variables and streams a chat completion:

    curl -N -X POST http://localhost:4000/prompts/test \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "dotprompt_content": "---\nmodel: claude-sonnet-5-5\ntemperature: 0.3\n---\nYou are a support agent. Greet {{customer_name}} and resolve: {{issue}}.",
    "prompt_variables": {"customer_name": "Jane", "issue": "double charge on order 4411"},
    "conversation_history": [{"role": "user", "content": "I was charged twice"}]
    }'

    Expected result: a stream of data: lines in the same format as /chat/completions with stream: true, ending in data: [DONE]. Nothing is saved.

  3. Save it. Click Update. Over the API, PUT /prompts/{prompt_id} saves the body as the next version in the environment named in prompt_info.environment:

    curl -X PUT http://localhost:4000/prompts/support-reply \
    -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 200 with the stored prompt and version 3. The previous versions are untouched. To change only part of a prompt, PATCH /prompts/{prompt_id}?environment=development takes just the fields you send, merges them field by field into the latest version of that environment (or into the version a .vN suffix on the id names), and saves the result as the next version with you as its author.

  4. Read the history. Open the prompt's detail page. The Version History table under Overview lists each version of the selected environment with its author and date, and clicking a row loads it. In the Prompt Studio, History opens the same list as a side panel. Over the API:

    curl "http://localhost:4000/prompts/support-reply/versions?environment=development" \
    -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result: {"prompts": [...]} with one entry per version, newest first, each carrying version, environment and created_by. Proxy admins and admin viewers only.

Environments​

Each environment has its own version line. A prompt saved in development does not exist in production until it is saved there too. The gateway accepts any environment name, so a typo such as prod starts a separate version line that requests without an environment never get. Stick to development, staging and production, which are the names the Prompt Studio offers.

Production is a protected environment by default, so you do not save to it directly. You save in development or staging and then promote the tested version, see prompt operations.

  1. In the Prompt Studio, switch the header selector to Staging and click Update. The content is saved as the next staging version. Over the API, send the same PUT /prompts/{prompt_id} body with "prompt_info": {"prompt_type": "db", "environment": "staging"}.
  2. Run an eval of that staging version, then on the prompt's detail page click Promote, pick staging to production and paste the eval run id. A direct save to production answers 409 The production environment is protected. ....

Expected result: the detail page shows a production button next to development, each with its latest version number, and the row for the production copy appears in the list with the production badge. Requests that send prompt_environment: "production" get this copy. A request that sends no environment gets production when it exists, otherwise staging, otherwise development. So once a production copy exists, a development application that sends no environment gets production too, and its edits saved in development never reach it. Point every application at its environment explicitly.

Pin a version in a request​

By default a request gets the latest version of the prompt in its environment. To hold an integration on a known version, send prompt_version:

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_version": 1,
"prompt_environment": "production",
"prompt_variables": {"customer_name": "Jane", "issue": "double charge on order 4411"},
"messages": [{"role": "user", "content": "I was charged twice"}]
}'

Expected result: the request renders production version 1 whatever the latest version is. The request log records the prompt id, not the version, so keep the pin in the request when you need to know which version answered. GET /prompts/support-reply.v1/info reads that version's template. Get Code on the detail page has a With Version tab that produces this call.

Upload a prompt file​

A prompt written as a .prompt file can be uploaded instead of typed. In the Admin UI click Upload .prompt File on the Prompts page, enter the Prompt ID, pick the file and click Create Prompt. The dialog first converts the file to JSON with POST /utils/dotprompt_json_converter and then creates the prompt. Over the API:

curl -X POST http://localhost:4000/utils/dotprompt_json_converter \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-F "file=@support-reply.prompt"

Expected result: {"prompt_id": "support-reply", "json_data": {"content": "You are a support agent. ...", "metadata": {"model": "claude-sonnet-5-5", "temperature": 0.3}}}. The converter's prompt_id comes from the file name, while the upload dialog stores the prompt under the Prompt ID you typed, and json_data holds the template body as content and the front matter as metadata. The converter only reads the file and stores nothing.

To create the prompt over the API, send the file's text as spanway_params.dotprompt_content with prompt_integration set to dotprompt:

jq -n --rawfile body support-reply.prompt \
'{prompt_id: "support-reply", spanway_params: {prompt_integration: "dotprompt", dotprompt_content: $body}, prompt_info: {prompt_type: "db"}}' \
| curl -X POST http://localhost:4000/prompts \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d @-

Expected result: the new prompt, with prompt_id support-reply and version 1.

{{ops:^/prompts/{prompt_id}/versions$|^/prompts/test$|^/utils/dotprompt_json_converter$}}

Errors​

StatusWhereMeaningFix
400 Model is required in dotprompt metadataPOST /prompts/test, the test chatThe front matter names no model.Add model: between the --- lines, or pick a model in the Prompt Studio.
400 No messages found in rendered promptPOST /prompts/testThe template rendered to nothing, usually because every line was front matter.Put the prompt text after the second ---.
Send button disabled in the test chatPrompt StudioA variable is still empty or a reply is streaming.Fill every variable the warning lists.
403 Only proxy admins can view prompt versionsGET /prompts/{prompt_id}/versionsThe key is not a proxy admin or admin viewer.Use an admin key.
404 No versions found for prompt ID support-replyGET /prompts/{prompt_id}/versionsNo version exists, or none in the environment asked for.Check the id and drop the environment filter.
409 The production environment is protected. ...POST, PUT, PATCH and DELETE on prompts, UpdateThe environment only takes promoted versions.Save in staging and promote, see prompt operations.
404 Prompt with ID support-reply not found in environment productionPATCH /prompts/{prompt_id}The environment has no version to patch yet.Save a full version there first with PUT.
400 Cannot update config prompts.PUT and PATCH, UpdateThe prompt comes from the config file. The check runs before the database is read, so a config file prompt never answers 404 here.Change the file, or create a database prompt with another id.
400 File must have .prompt extensionPOST /utils/dotprompt_json_converterThe upload has another extension.Rename the file to .prompt.
Reply ignores the promptA request with prompt_environmentThe environment has no version yet. The gateway does not refuse the request, it is sent without a stored template.Save a version in that environment, or drop prompt_environment.
A request keeps using the old contentAny requestThe application sends prompt_version, or points at an environment you did not save to.Remove the pin, or save the content in that environment.

Logs​

The version routes log the same ERROR lines as the rest of prompt management, Error updating prompt: <error>, Error patching prompt: <error> and Error testing prompt: <error>, each meaning the route answered 500 and nothing was saved. See prompt management logs. Every saved version writes an audit row with the template replaced by its hash.

  • Prompt operations for protected production, eval-gated promotion, version diffs, partials, change alerts and Git sync.
  • Prompt management for creating a prompt and the request fields.
  • Prompts page for every control of the Prompt Studio, the version history panel and the generated code dialog.
  • Logging for the prompt fields recorded on each request.
  • Audit logs for the rows each saved version writes.