How It Works
API variables enable seamless integration with external services:- Define the Request: Set the URL, HTTP method, headers, and body for your API call
- Map to Dataset: If you have linked dataset on playground, use placeholders like
{{userId}}within the API configuration. These are automatically resolved from your dataset columns at runtime - Execution: The system performs the HTTP request and replaces the variable in your prompt with the API response
Configuration Details
API variables support comprehensive HTTP request configuration:| Feature | Supported Options / Limits |
|---|---|
| HTTP Methods | GET, POST, PUT, PATCH, DELETE |
| Injection Points | URL, Headers, Query Params, Request Body |
| Data Types | Handles JSON, Plain Text, Images, and PDFs |
| Security | Use secretHeaders to obfuscate sensitive keys/tokens |
| Reliability | 30s timeout; 3 retries with exponential backoff (starting at 1s) |
Dataset Integration
When API variables are linked to datasets, they function as Dynamic Columns:- Row-Level Execution: Each row in your dataset triggers its own unique API request
- Variable Resolution: Placeholders in your API configuration (like
{{userId}}in the URL) are replaced with values from the corresponding dataset row - Persistence: Results are stored within the dataset cells and can be used for subsequent evaluations
Example
If your dataset has auserId column and your API variable is configured with:
userId value.
Execution Behavior
- Sequential vs. Parallel: API variables that depend on other variables run sequentially, while independent API variables run in parallel
- Timeout: Each API request has a 30-second timeout
- Retries: Failed requests are automatically retried up to 3 times with exponential backoff (starting at 1 second)
Error Handling
| Error Type | Cause | Result |
|---|---|---|
| Missing Column | Variable references a non-existent dataset column | Execution fails before the run starts |
| API Failure | 4xx/5xx errors or timeout | Parent prompt fails; error propagates |
| Invalid URL | Malformed URL after variable resolution | API request fails |
Best Practices
- Security: Always mark Authorization tokens and API keys as
secretHeadersto prevent them from being exposed in logs - Naming: Use descriptive names (e.g.,
{{user_purchase_history}}instead of{{var1}}) - Testing: Test API endpoints independently before integrating them into your prompts
Variable names must follow specific naming rules. See Variable Name Constraints for detailed information about allowed characters and naming conventions.