Request Mapping
Request body templates define how Rhesis formats its platform variables into the JSON structure your API expects. Templates use Jinja2 syntax.
Jinja2 Basics
Place input wherever your API expects the user query:
For nested message formats:
The tojson Filter
Use tojson for optional fields or when a value might be null:
tojson ensures proper JSON serialization: None → null, strings are quoted, objects and arrays are serialized correctly.
Raw Body Templates
If your template renders to a JSON object with a __body__ key, Rhesis unwraps it and sends the value as the raw request body. This is useful for APIs that expect a plain string or a non-JSON payload rather than a JSON object.
File Format Filters
When tests include file attachments, the files variable contains an array of objects with filename, content_type, and data (base64-encoded). See Multi-modal Testing for the full type and size matrix.
Most provider APIs expect the user message content field to contain both the text and the files together. Use the content filters for this — they combine input and files into a single content array automatically:
| Filter | Provider |
|---|---|
anthropic_content | Anthropic Claude |
openai_content | OpenAI |
gemini_parts | Google Gemini |
If your API separates text and files into different fields, use the file-only filters instead — these convert files to the provider format without including the text:
| Filter | Provider |
|---|---|
to_anthropic | Anthropic Claude |
to_openai | OpenAI |
to_gemini | Google Gemini |
When no files are attached, all filters return an empty array ([]).
Multi-turn conversation format filters — convert an OpenAI-style messages array to a provider-specific format:
| Filter | Description |
|---|---|
to_gemini_contents | Converts to Gemini contents format |
to_anthropic_messages | Converts to Anthropic messages format |
See Examples for complete request and response configurations with file attachments.
Multi-Turn Conversations
Rhesis supports two conversation patterns:
- Stateful — your API manages session state. It returns a conversation ID which Rhesis passes back on subsequent requests.
- Stateless — no server-side state. The caller sends the full conversation history with every request. Rhesis manages this internally.
Rhesis detects which mode to use based on your template configuration.
Stateful Endpoints
Map the conversation field from the API response:
Include the conversation variable in the request template so Rhesis passes it back on subsequent turns:
tojson ensures the value is null on the first turn and a properly quoted string on subsequent turns.
Supported conversation field names (Rhesis normalizes all to conversation_id internally):
- Tier 1:
conversation_id,session_id,thread_id,chat_id - Tier 2:
dialog_id,dialogue_id,context_id,interaction_id
How it works:
- First request sent without a conversation ID (or with
null) - Rhesis extracts the conversation ID from the response
- Subsequent requests for the same conversation include the ID automatically
Example Flow (Stateful)
Stateless Endpoints
Use the messages template variable. Rhesis detects this and switches to stateless conversation management:
Single-turn auto-population — for single test runs (outside a multi-turn conversation), Rhesis automatically builds the messages array from the test input and system prompt. You do not need to provide the array manually.
Rhesis builds the messages array incrementally during multi-turn execution:
System prompt handling — Rhesis extracts system_prompt from the template, prepends it to messages as the first system role entry, and strips the system_prompt field from the request body before sending. Your API only receives the standard messages array:
Comparison
| Stateful | Stateless | |
|---|---|---|
| Server manages context | Yes | No |
| Request includes | conversation_id + input | messages array |
| Detected by | Conversation field in response mapping | {{ messages }} in request template |
| Example providers | Custom chatbots, managed services | OpenAI, Anthropic, Google AI |
Per-Turn Response Fields
For both patterns, Rhesis captures response fields on every turn. These are available to conversational metrics during evaluation:
| Field | Per-turn behavior |
|---|---|
output | Assistant response text for this turn |
context | Retrieval context (e.g., RAG sources) |
metadata | Structured metadata (e.g., confidence, model info) |
tool_calls | Tool/function calls made during this turn |
Next Steps
- See Response Mapping to extract values from API responses
- Browse Examples for complete provider configurations