Skip to main content
We’re transitioning to OpenAPI spec-driven documentation. The new API Reference features interactive “Try It” functionality and auto-generated examples, and you can access the full OpenAPI spec there. This page will remain available for detailed descriptions during the transition.

The Freeplay HTTP API provides programmatic access to all platform capabilities. While the Freeplay SDKs offer language-native bindings for common operations, the API exposes the full range of functionality.
SDK vs. API: The Freeplay SDKs are designed to cover the most common integration patterns—prompt management, recording completions, and running tests. The HTTP API is a superset that includes additional capabilities like bulk operations, advanced search, and administrative endpoints.

Getting Started

Base URL

Your API root is your Freeplay instance URL plus /api/v2/.

Authentication

Authenticate requests using your API key in the Authorization header:
API keys are managed at https://app.freeplay.ai/settings/api-access.

Error Handling

Freeplay uses standard HTTP status codes:
For 500 errors, retry up to three times with at least 5 seconds between attempts. Do not retry 400-level errors—these indicate client issues that won’t resolve on retry.
Example Error Response:

Observability

Freeplay organizes observability data in a hierarchy:
  • Sessions are created implicitly when you record your first completion with a session ID, or you can create one
  • Traces are optional but required for agent workflows—they group related completions together
  • Completions are the atomic unit: a prompt sent to an LLM and its response
For conceptual background, see Sessions, Traces, and Completions. For SDK usage, see Organizing Principles.

Sessions

Sessions group related LLM completions together—typically representing a user conversation or workflow. Base URL: /api/v2/projects/<project-id>/sessions
Sessions are created implicitly when you record a completion. You only need to generate a session ID (UUID v4) client-side. For SDK usage, see Sessions.

Retrieve Sessions

GET / Returns sessions with their completions, ordered by most recent first. Query Parameters:
Response:

Delete Session

DELETE /<session-id> Permanently deletes a session and all associated completions.
This operation cannot be undone.

Traces

Traces group related completions within a session. They’re essential for agent workflows where multiple LLM calls work together to accomplish a task. Base URL: /api/v2/projects/<project-id>/sessions/<session-id>/traces For SDK usage, see Traces.

Record a Trace

POST /id/<trace-id> Records a trace within a session. Like sessions, traces are created implicitly—generate a UUID v4 client-side and use it as the trace ID. Request Payload:
When building agents, record completions with trace_info to associate them with a trace, then call this endpoint to finalize the trace with its output.

Completions

Completions are the atomic unit of observability—a single LLM call with its prompt and response. Base URL: /api/v2/projects/<project-id>/sessions/<session-id>/completions For SDK usage, see Recording Completions.

Record a Completion

POST / Records an LLM completion to a session. This is the primary endpoint for logging LLM interactions. Request Payload:
Response:
With Trace Association: To associate a completion with a trace (for agent workflows), include trace_info:

Prompt Templates

Create, retrieve, and manage prompt templates programmatically. For conceptual background on prompt management patterns, see Prompt Management. Base URL: /api/v2/projects/<project-id>/prompt-templates

Create Prompt Template

POST / Creates a new prompt template (without any versions). Typically used when you want to create a template first, then add versions separately. NOTE: The same objective can be accomplished using the create_template_if_not_exists parameter on the Create Version by Name endpoint below. Request Payload:
Response:

List Prompt Templates

GET / Returns all prompt templates in a project with pagination. Query Parameters:

Create Version by Name

POST /name/<template-name>/versions Creates a new prompt version by template name. This is the recommended endpoint for CI/CD workflows because it supports creating the template automatically if it doesn’t exist. Query Parameters: Request Payload:
Response:
Code-managed prompts: Use the create_template_if_not_exists=true parameter in your CI/CD pipeline to automatically sync prompts from your codebase to Freeplay. See Code as source of truth for the full workflow.

Retrieve by Name

POST /name/<template-name> Fetches a prompt template in one of three forms: Query Parameters: Formatted Prompt (most common):
Response:

Retrieve by Version ID

POST /id/<template-id>/versions/<version-id> Fetch a specific prompt version. Useful for pinning to a known version.

Retrieve All Templates

GET /all/<environment-name> Returns all prompt templates in an environment.

Create Version by ID

POST /id/<template-id>/versions Adds a new version to an existing prompt template (identified only by ID). Deployed to latest by default. Request Payload:

Update Environments

POST /id/<template-id>/versions/<version-id>/environments Assign a version to additional environments.
For SDK-based prompt management, see Prompts. For the conceptual guide on managing prompts programmatically, see Code as source of truth.

Test Runs

Execute batch tests using saved datasets. Base URL: /api/v2/projects/<project-id>/test-runs

Create Test Run

POST / Creates a new test run from an existing dataset.
Response:

Retrieve Test Run Results

GET /id/<test-run-id>
Response:

List Test Runs

GET /
For SDK-based testing, see Test Runs.

Customer Feedback

Record user feedback for completions and traces.

Completion Feedback

Base URL: /api/v2/projects/<project-id>/completion-feedback POST /id/<completion-id>

Trace Feedback

Base URL: /api/v2/projects/<project-id>/trace-feedback POST /id/<trace-id> Same parameters as completion feedback.
For SDK-based feedback, see Customer Feedback.

Search API

Query sessions, traces, and completions with powerful filtering. This functionality is API-only and not available through the SDKs.

Endpoints

All endpoints support pagination via page and page_size query parameters.

Filter Operators

Available Filters

Compound Filters

Combine filters using and, or, and not:

Additional API Endpoints

The following endpoints provide administrative and bulk operations not covered by the SDKs.

Projects

Base URL: /api/v2/projects

List All Projects

GET /all Returns all projects in your workspace.
Does not work with project-scoped API keys. Private projects are excluded.

Agents

Base URL: /api/v2/projects/<project-id>/agents

List Agents

GET /

Datasets

Base URL: /api/v2/projects/<project-id>/datasets

Retrieve Dataset Metadata

GET /name/<dataset-name> or GET /id/<dataset-id>

Retrieve Dataset Test Cases

GET /name/<dataset-name>/test-cases or GET /id/<dataset-id>/test-cases

Upload Test Cases

POST /id/<dataset-id>/test-cases
Maximum 100 test cases per request.

Completions Statistics

Base URL: /api/v2/projects/<project-id>/completions

Aggregate Statistics

POST /statistics Returns evaluation statistics across all prompts for a date range (max 30 days).

Statistics by Prompt

POST /statistics/<prompt-template-id> Same parameters as aggregate statistics, filtered to a specific prompt template.

Complete Examples

End-to-End LLM Interaction

This example fetches a prompt, calls OpenAI, and records the completion:

Executing a Test Run

Agent Workflow with Traces

This example shows how to record an agent workflow with multiple completions grouped by a trace:

Next Steps