Run a prompt's test cases
/v1/prompts/{slug}/test-cases/runRun a prompt's test cases.
Renders the prompt's default version (the production label, else the PUBLISHED version, else the highest version) with each test case's variables and sends it to the model on the given virtual key, one test case after another. A test case passes when its answer matches its expected_pattern (a regular expression, any case; plain text when it is not a valid one), or has no pattern. Each call is billed to the virtual key. A test case whose call fails is reported as failed with its error; the run itself still succeeds. Requires an admin of the prompt's workspace, or an organization admin.
Errors: 400 when the virtual key is unknown or not usable in the prompt's workspace, or the version has no model and no model_override is given; 404 when the prompt has no versions.
Authorization
AuthorizationBearer va_A platform API key (
va_...), created under Settings > API keys. Scoped to an organization or one workspace, with an admin or member role. Used by the management API.
Path parameters
slugstringrequiredthe prompt's slug
Query parameters
organizationstringrequiredslug of the organization that owns it
Request body application/json
the virtual key, and an optional model override
virtual_keystringrequiredSlug of the virtual key that runs the test cases (required), for example
vk-.... It must belong to the prompt's organization and, when it is scoped to a workspace, to the prompt's workspace (400 otherwise). Each test case is one completion on this key, with its usage and cost.model_overridestringA model to use instead of the version's
model. Required when the version has no model (400 otherwise).
Responses
prompt_slugstringSlug of the prompt.
version_numberinteger<int32>The version that was tested: the one the
productionlabel points at, else the PUBLISHED version, else the highest version number.virtual_keystringSlug of the virtual key the test cases ran on.
test_case_countinteger<int32>Number of test cases run.
pass_countinteger<int32>Number of test cases that passed.
fail_countinteger<int32>Number of test cases that failed, including calls that errored.
total_cost_usdnumber<double>Total cost of the run in USD, the sum of the test cases'
cost_usd. Null when the prompt has no test cases.resultsobject[]One result per test case, in the order they ran.
Child attributes
test_case_idstringId (UUID) of the test case.
namestringThe test case's name.
passedbooleanWhether the answer matched the test case's
expected_pattern.falsewhen the call failed.response_textstringThe model's answer text. Null when the call failed.
latency_msinteger<int64>How long the call took, in milliseconds. Null when it failed.
prompt_tokensinteger<int32>Input tokens the call used. Null when it failed or the provider reported no usage.
completion_tokensinteger<int32>Output tokens the call generated. Null when it failed or the provider reported no usage.
cost_usdnumber<double>The provider cost of the call in USD, at list price. Null when the call failed or the model has no price.
error_messagestringWhy the call failed. Null when it succeeded.
pattern_matchedbooleanWhether the answer matched
expected_pattern(truewhen the test case has no pattern and the call succeeded). Same aspassed.