HTTP Endpoints
TrustTest’s HttpModel
provides a flexible way to connect to any LLM API accessible through HTTP.
This is currently the only model type that can be fully utilized through the TrustTest web UI.
Overview
The HttpModel
class allows you to:
- Connect to any REST API endpoint
- Configure custom headers, payloads, and authentication
- Handle multi-turn conversations
- Process various response formats (JSON, plain text)
- Implement error handling and retry mechanisms
Basic Usage
Here’s a simple example of how to configure an HttpModel:
Configuration Options
The HttpModel
accepts several configuration options:
Required Parameters
url
: The API endpoint URLpayload_config
: Configures how messages are formatted in the request payload
Optional Parameters
headers
: HTTP headers to include in the requesttoken_config
: Configuration for authentication token generationerror_config
: How to handle error responsesresponse_regex
: Extract specific content from responsesconcatenate_field
: Extract nested fields from JSON responsesretry_config
: Configure automatic retries for failed requests
Payload Configuration
The PayloadConfig
class configures how messages are formatted in requests:
format
: The structure of your payload, with placeholders for message contentmessage_regex
: Pattern to replace with the actual message (default:{{ message }}
)date_regex
: Pattern to replace with the current date (default:{{ date }}
)params
: URL query parameters to include in the requesttimeout
: Request timeout in seconds
Response Handling
HttpModel provides several ways to extract the response content:
concatenate_field
: Extract a specific field from JSON responses using dot notationresponse_regex
: Apply a regex pattern to extract specific content
For example, to extract the message content from a nested JSON response:
Example Implementation
This example shows how to create an HttpModel for a chat API endpoint:
Using HttpModel in Evaluation Scenarios
After configuring your model, you can use it in evaluation scenarios:
Configure Web UI
Currently, the HttpModel
is the only model type that can be used to run tests through the TrustTest web UI. This makes it an essential component for teams looking to set up continuous evaluation of their LLM APIs.
When configuring your model through the web UI, you’ll define the same HttpModel configuration but in YAML format in the Target section. Here’s an example of how your configuration should look:
This YAML configuration maps directly to the HttpModel parameters you would use in Python. Once configured, you should be able to run any test directly through the web UI with the same functionality as programmatic tests.
The web UI will provide fields for:
- API endpoint URL
- Headers (including authentication)
- Payload format
- Response extraction configuration
Advanced Features
Authentication with TokenConfig
For APIs requiring token-based authentication with expiration:
Error Handling
Configure how errors are returned as a normal response, this is useful for firewall issues or other issues where you want to return a normal response instead of rising an error.
Retry Configuration
Set up automatic retries for failed requests: