> For the complete documentation index, see [llms.txt](https://docs.three.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.three.dev/api-reference/render-prompt.md).

# Render Prompt

Render a prompt by substituting variable values into the active published version's message templates. Use this endpoint to retrieve the final prompt text from three.dev instead of hardcoding it in your application.

## Request

```
POST /api/v1/prompts/{slug}/render
```

**Path parameters:**

| Parameter | Type   | Description      |
| --------- | ------ | ---------------- |
| `slug`    | string | The prompt slug. |

**Query parameters:**

| Parameter | Type    | Required | Description                                                                     |
| --------- | ------- | -------- | ------------------------------------------------------------------------------- |
| `version` | integer | No       | Pin to a specific published version. Defaults to the active version if omitted. |

**Headers:**

| Header          | Required | Value                        |
| --------------- | -------- | ---------------------------- |
| `Authorization` | Yes      | `Bearer <THREE_DEV_API_KEY>` |
| `Content-Type`  | Yes      | `application/json`           |

**Body:**

| Field           | Type   | Required | Description                                                                                                                                                               |
| --------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `use_case_slug` | string | Yes      | The use case this prompt belongs to.                                                                                                                                      |
| `variables`     | object | No       | Key-value map of variable names to substitution values. Defaults to an empty map. All variables referenced in the template must be provided; extra variables are ignored. |

**Example:**

```bash
curl -X POST https://api.three.dev/api/v1/prompts/hotel-booking-system/render \
  -H "Authorization: Bearer <THREE_DEV_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "use_case_slug": "hotel-booking-assistant",
    "variables": {
      "customer_name": "Jane",
      "role": "hotel booking"
    }
  }'
```

## Response

**Success** (HTTP 200):

```json
{
  "slug": "hotel-booking-system",
  "version": 3,
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful hotel booking assistant. The customer's name is Jane.",
      "position": 0
    }
  ]
}
```

| Field      | Type    | Description                                           |
| ---------- | ------- | ----------------------------------------------------- |
| `slug`     | string  | The prompt slug.                                      |
| `version`  | integer | The version that was rendered.                        |
| `messages` | array   | The rendered messages with all variables substituted. |

Each message contains:

| Field      | Type    | Description                                     |
| ---------- | ------- | ----------------------------------------------- |
| `role`     | string  | The message role (system, user, or assistant).  |
| `content`  | string  | The rendered content with variables replaced.   |
| `position` | integer | The message's position in the prompt (0-based). |

## Error responses

| Code | Meaning                                                                                                        |
| ---- | -------------------------------------------------------------------------------------------------------------- |
| 400  | Missing variables — the error lists every variable referenced in the template but not provided in the request. |
| 401  | Unauthorized — missing or invalid API key.                                                                     |
| 404  | No published version exists for this prompt and use case, or the pinned version does not exist.                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.three.dev/api-reference/render-prompt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
