> For the complete documentation index, see [llms.txt](https://docs.podtorrent.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.podtorrent.com/using-the-api/cached-prompts.md).

# Cached prompts

Many apps start every conversation the same way: a long system prompt, or an agent framework's instructions. Engines can keep that opening processed so they don't redo the work each time. PodTorrent lets you take advantage of it.

## How it works

1. You get an id for your opening from `POST /v1/prompts`.
2. You share that id with node operators, so they can keep the opening cached and advertise it.
3. When your request starts with that exact opening, the gateway sends it to a node that has it cached, ahead of other nodes.
4. Cached input tokens are billed at that node's cached price, which is usually lower.

You don't change your requests at all. Matching happens automatically.

## Get the id

Send the opening messages, exactly as your app sends them:

```bash
curl https://api.podtorrent.com/v1/prompts \
  -H "Authorization: Bearer $PODTORRENT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "system", "content": "You are a helpful support agent for ..."}]}'
```

```json
{ "object": "prompt", "sha256": "9c1e…", "messages": 1 }
```

## Matching rules

* The opening is the first 1 to 8 messages of the conversation.
* Only `role` and `content` count, and they must match exactly. One changed character, such as a date in the system prompt, gives a different id.
* A match means the request goes to that node first. Whether the engine really reuses its cache is up to the engine; you'll see the result in `usage.prompt_tokens_details.cached_tokens` if the engine reports it.

To see which openings nodes advertise today, look at `cached_prompts` in [network offers](/using-the-api/models-and-offers.md#network-offers). The `X-PodTorrent-Cache-Hit` response header tells you if a request matched.

Operators: see [Advertise cached prompts](/running-a-node/cached-prompts.md).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.podtorrent.com/using-the-api/cached-prompts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
