API Reference

Complete reference for the FetchPrompt REST API — endpoints, authentication, request/response formats, and error codes.

API Reference

The FetchPrompt REST API lets you fetch prompt content at runtime from any application. All endpoints are served from the Edge for low latency worldwide.

Base URL: https://www.fetchprompt.com/api/v1

Authentication

All API requests require a Bearer token in the Authorization header:

Authorization: Bearer fp_prod_your_key_here

The API key determines both the organization and environment (Stage or Production) for the request. See API Keys for details on creating and managing keys.

Endpoints


List all prompts

Returns all prompts for the organization and environment associated with your API key.

GET /api/v1/prompts

Headers:

HeaderRequiredDescription
AuthorizationYesBearer {api_key}

Response 200 OK:

{
  "data": [
    {
      "slug": "customer-support-bot",
      "name": "Customer Support Bot",
      "version": 3,
      "environment": "prod",
      "updated_at": "2026-02-24T10:30:00Z"
    },
    {
      "slug": "email-subject-generator",
      "name": "Email Subject Generator",
      "version": 1,
      "environment": "prod",
      "updated_at": "2026-02-23T15:00:00Z"
    }
  ]
}

Prompts are ordered by updated_at (most recently updated first).


Fetch a prompt (GET)

Fetches a single prompt by slug. Supports variable interpolation via query parameters and ETag caching.

GET /api/v1/prompts/{slug}

Path parameters:

ParameterDescription
slugThe prompt's URL-friendly identifier (e.g., customer-support-bot)

Query parameters (optional):

Any query parameter is treated as a variable for interpolation. For example:

GET /api/v1/prompts/my-prompt?user_name=Sarah&tone=friendly

This replaces {{user_name}} with Sarah and {{tone}} with friendly in the prompt content.

Headers:

HeaderRequiredDescription
AuthorizationYesBearer {api_key}
If-None-MatchNoETag value for conditional requests

Response 200 OK:

{
  "slug": "customer-support-bot",
  "name": "Customer Support Bot",
  "content": "You are a helpful customer support agent. The customer's name is Sarah.",
  "version": 3,
  "environment": "prod"
}

If some variables in the prompt were not provided, the response includes a missing_variables field:

{
  "slug": "customer-support-bot",
  "name": "Customer Support Bot",
  "content": "You are a helpful customer support agent for {{company_name}}. The customer's name is Sarah.",
  "version": 3,
  "environment": "prod",
  "missing_variables": ["company_name"]
}

Response 304 Not Modified:

Returned when the If-None-Match header matches the current ETag. No body is returned.

Response headers:

HeaderDescription
ETagContent hash for conditional requests (e.g., "a1b2c3d4e5f67890")
Cache-Controlpublic, max-age=60
X-RateLimit-LimitMonthly API call limit (e.g., 30000)
X-RateLimit-RemainingCalls remaining this month
X-RateLimit-ResetUnix timestamp when the limit resets

Render a prompt (POST)

Fetches a prompt and renders it with variables provided in a JSON body. Use this when you have many variables or values that contain special characters.

POST /api/v1/prompts/{slug}

Path parameters:

ParameterDescription
slugThe prompt's URL-friendly identifier

Headers:

HeaderRequiredDescription
AuthorizationYesBearer {api_key}
Content-TypeYesapplication/json
If-None-MatchNoETag value for conditional requests

Request body:

{
  "user_name": "Sarah",
  "company_name": "Acme Inc",
  "tone": "friendly"
}

Pass variables as a flat JSON object. The body is optional — if omitted or empty, the prompt content is returned without interpolation.

Response 200 OK:

{
  "slug": "customer-support-bot",
  "name": "Customer Support Bot",
  "content": "You are a helpful customer support agent for Acme Inc. The customer's name is Sarah. Respond in a friendly tone.",
  "version": 3,
  "environment": "prod"
}

If some variables in the prompt were not provided, the response includes a missing_variables field:

{
  "slug": "customer-support-bot",
  "name": "Customer Support Bot",
  "content": "You are a helpful customer support agent for {{company_name}}. The customer's name is Sarah. Respond in a friendly tone.",
  "version": 3,
  "environment": "prod",
  "missing_variables": ["company_name"]
}

Response 304 Not Modified:

Returned when the If-None-Match header matches the current ETag. No body is returned.

Response headers:

HeaderDescription
ETagContent hash for conditional requests (e.g., "a1b2c3d4e5f67890")
Cache-Controlpublic, max-age=60
X-RateLimit-LimitMonthly API call limit (e.g., 30000)
X-RateLimit-RemainingCalls remaining this month
X-RateLimit-ResetUnix timestamp when the limit resets

Error responses

All error responses follow this format:

{
  "error": "Error message describing what went wrong"
}
Status CodeErrorDescription
400Invalid JSON body. Expected format: { "key": "value" }The POST request body is not valid JSON
401Missing or invalid API keyNo Authorization header or the header doesn't start with Bearer
401Invalid API keyThe API key is not recognized or has been revoked
404Prompt not foundNo prompt exists with the given slug in the API key's organization and environment
429Rate limit exceededThe organization has exceeded its monthly API call limit
500Failed to fetch promptsAn internal error occurred while querying the database

Code examples