The Scenarios API allows you to create, run, and manage test scenarios for your tool collections.
GET /api/scenarios
Retrieve a paginated list of public scenarios with optional filtering.
limit - Number of results (default: 20, max: 50)offset - Pagination offsetcollectionId - Filter by collection IDtags - Filter by tags (comma-separated)sortBy - Sort field: qualityScore, totalRuns, createdAt, lastRunAtcurl "https://tpmjs.com/api/scenarios?limit=10&sortBy=qualityScore"{
"data": [
{
"id": "clu123abc456",
"collectionId": "clx789def",
"prompt": "Scrape the main article content from a news website...",
"name": "Scrape article content",
"description": "Tests web scraping capability on news sites",
"tags": ["web-scraping", "content-extraction"],
"qualityScore": 0.85,
"totalRuns": 12,
"lastRunAt": "2024-01-20T10:30:00Z",
"lastRunStatus": "pass",
"consecutivePasses": 5,
"consecutiveFails": 0,
"createdAt": "2024-01-01T00:00:00Z",
"collection": {
"id": "clx789def",
"name": "Web Scraping Toolkit",
"slug": "web-scraping-toolkit",
"username": "johndoe"
}
}
],
"pagination": {
"limit": 10,
"offset": 0,
"hasMore": true
}
}GET /api/scenarios/:id
Retrieve detailed information about a specific scenario.
id - Scenario IDcurl "https://tpmjs.com/api/scenarios/clu123abc456"{
"success": true,
"data": {
"id": "clu123abc456",
"collectionId": "clx789def",
"prompt": "Scrape the main article content from a news website and extract the headline, author, publication date, and body text.",
"name": "Scrape article content",
"description": "Tests web scraping capability on news sites",
"tags": ["web-scraping", "content-extraction", "news"],
"assertions": null,
"qualityScore": 0.85,
"totalRuns": 12,
"lastRunAt": "2024-01-20T10:30:00Z",
"lastRunStatus": "pass",
"consecutivePasses": 5,
"consecutiveFails": 0,
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-20T10:30:00Z",
"collection": {
"id": "clx789def",
"name": "Web Scraping Toolkit",
"slug": "web-scraping-toolkit"
}
}
}GET /api/collections/:id/scenarios
Retrieve all scenarios for a specific collection.
id - Collection IDlimit - Number of results (default: 20, max: 50)offset - Pagination offsetcurl "https://tpmjs.com/api/collections/clx789def/scenarios"{
"success": true,
"data": {
"scenarios": [
{
"id": "clu123abc456",
"name": "Scrape article content",
"prompt": "Scrape the main article content...",
"qualityScore": 0.85,
"totalRuns": 12,
"lastRunStatus": "pass",
"tags": ["web-scraping"]
}
]
}
}POST /api/scenarios
Create a new scenario manually. Requires authentication and collection ownership.
{
"collectionId": "clx789def",
"prompt": "Search for weather information in Tokyo and return the current temperature",
"name": "Tokyo weather lookup",
"description": "Tests weather search functionality",
"tags": ["weather", "search", "api"]
}const response = await fetch('https://tpmjs.com/api/scenarios', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
collectionId: 'clx789def',
prompt: 'Search for weather information in Tokyo',
name: 'Tokyo weather lookup',
tags: ['weather', 'search']
})
});
const { data: scenario } = await response.json();
console.log('Created scenario:', scenario.id);POST /api/collections/:id/scenarios/generate
AI-generate scenarios based on the collection's tools. Requires authentication and collection ownership.
id - Collection ID{
"count": 3,
"skipSimilarityCheck": false
}curl -X POST "https://tpmjs.com/api/collections/clx789def/scenarios/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"count": 3}'{
"success": true,
"data": {
"scenarios": [
{
"scenario": {
"id": "clu111aaa",
"prompt": "Scrape the main article content from a news website...",
"name": "News article extraction",
"tags": ["web-scraping", "content-extraction"]
},
"similarity": {
"maxSimilarity": 0.15,
"mostSimilar": null
}
},
{
"scenario": {
"id": "clu222bbb",
"prompt": "Extract all product images from an e-commerce page...",
"name": "E-commerce image extraction",
"tags": ["web-scraping", "images", "e-commerce"]
},
"similarity": {
"maxSimilarity": 0.72,
"mostSimilar": {
"id": "clu000xxx",
"name": "Product page scraping"
}
}
}
]
}
}When similarity.maxSimilarity exceeds 0.7, the scenario is similar to an existing one. The mostSimilar field shows which scenario it overlaps with.
POST /api/scenarios/:id/run
Execute a scenario and return the results. Requires authentication. Consumes one run from your daily quota.
id - Scenario IDcurl -X POST "https://tpmjs.com/api/scenarios/clu123abc456/run" \
-H "Authorization: Bearer YOUR_API_KEY"{
"success": true,
"data": {
"runId": "run_abc123def456",
"status": "completed",
"success": true,
"evaluator": {
"model": "claude-3-5-sonnet-latest",
"verdict": "pass",
"reason": "The agent successfully extracted the article headline, author name, publication date, and full body text from the news website. All required fields were present and correctly formatted."
},
"usage": {
"inputTokens": 892,
"outputTokens": 353,
"totalTokens": 1245,
"executionTimeMs": 2341
},
"timestamps": {
"startedAt": "2024-01-20T10:30:00Z",
"completedAt": "2024-01-20T10:30:02Z",
"createdAt": "2024-01-20T10:30:00Z"
},
"quotaRemaining": 46
}
}{
"success": true,
"data": {
"runId": "run_xyz789",
"status": "completed",
"success": false,
"evaluator": {
"model": "claude-3-5-sonnet-latest",
"verdict": "fail",
"reason": "The agent was unable to complete the task. The target website returned a 403 Forbidden error, preventing the scraping operation."
},
"usage": {
"inputTokens": 456,
"outputTokens": 123,
"totalTokens": 579,
"executionTimeMs": 3102
},
"quotaRemaining": 45
}
}GET /api/scenarios/:id/runs
Retrieve the run history for a scenario. Requires authentication if the scenario belongs to a private collection.
id - Scenario IDlimit - Number of results (default: 10, max: 50)offset - Pagination offsetcurl "https://tpmjs.com/api/scenarios/clu123abc456/runs?limit=5" \
-H "Authorization: Bearer YOUR_API_KEY"{
"data": [
{
"id": "run_abc123",
"status": "completed",
"success": true,
"evaluator": {
"model": "claude-3-5-sonnet-latest",
"verdict": "pass",
"reason": "Successfully extracted article content"
},
"assertions": null,
"usage": {
"inputTokens": 892,
"outputTokens": 353,
"totalTokens": 1245,
"executionTimeMs": 2341
},
"timestamps": {
"startedAt": "2024-01-20T10:30:00Z",
"completedAt": "2024-01-20T10:30:02Z",
"createdAt": "2024-01-20T10:30:00Z"
}
}
],
"pagination": {
"limit": 5,
"offset": 0,
"hasMore": true
}
}POST /api/scenarios/check-similarity
Check if a prompt is similar to existing scenarios in a collection. Useful before creating manual scenarios to avoid duplicates.
{
"prompt": "Scrape article headlines from a news website",
"collectionId": "clx789def"
}{
"success": true,
"data": {
"maxSimilarity": 0.78,
"similar": [
{
"id": "clu123abc456",
"name": "Scrape article content",
"prompt": "Scrape the main article content from a news website...",
"similarity": 0.78
},
{
"id": "clu789xyz",
"name": "Extract news headlines",
"prompt": "Get all headlines from the front page of a news site...",
"similarity": 0.65
}
]
}
}A maxSimilarity above 0.7 indicates significant overlap with existing scenarios. Consider modifying your prompt to test different aspects of your tools.
GET /api/scenarios/featured
Retrieve featured scenarios for the homepage showcase. Returns a mix of high-quality, diverse, and recently successful scenarios.
limit - Number of results (default: 10, max: 20)curl "https://tpmjs.com/api/scenarios/featured?limit=5"{
"success": true,
"data": [
{
"id": "clu123abc456",
"name": "Scrape article content",
"qualityScore": 0.95,
"totalRuns": 50,
"lastRunStatus": "pass",
"collection": {
"name": "Web Scraping Toolkit",
"slug": "web-scraping-toolkit",
"username": "johndoe"
}
}
]
}Common error codes and responses
{
"success": false,
"error": "Unauthorized",
"message": "API key is required for this endpoint"
}{
"success": false,
"error": "Forbidden",
"message": "You don't have permission to access this scenario"
}{
"success": false,
"error": "Not Found",
"message": "Scenario not found"
}{
"success": false,
"error": "Rate Limit Exceeded",
"message": "Daily scenario run quota exceeded. Resets at midnight UTC.",
"quotaRemaining": 0,
"resetAt": "2024-01-21T00:00:00Z"
}