> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Wren API

> Run Wren from your own code, and read the recommendations it raises on your projects.

The Wren API has two parts. **Turns** let you send Wren a prompt and stream its work back, exactly as the chat panel in Agent Studio does. **Recommendations** let you read what Wren has found on a project, so you can show it in your own tools.

## Endpoints

| Endpoint | What it does |
| - | - |
| [Send a turn](https://docs.poly.ai/api-reference/wren/endpoint/send-turn.md) | Send a prompt, or answer a question Wren asked, and stream the run back |
| [List recommendations](https://docs.poly.ai/api-reference/wren/endpoint/recommendations/list-recommendations.md) | List a project’s recommendations, with filters and sorting |
| [Get a recommendation](https://docs.poly.ai/api-reference/wren/endpoint/recommendations/get-recommendation.md) | Read one recommendation with its history |

## Authentication

All Wren API endpoints authenticate with the `x-api-key` header. Which kind of key you can use depends on the endpoint:

| Endpoint | Personal access token | Workspace API key |
| - | - | - |
| Send a turn | Yes | No |
| List recommendations | Yes | Yes |
| Get a recommendation | Yes | Yes |

A personal access token acts as you, with your permissions. A workspace API key acts with the permissions granted to that key. Either way, the key needs access to the project you name.

> [!NOTE]
>
> Create a personal access token from your profile menu in Agent Studio, under **Account** › **Personal access tokens**. If you don’t see the tab, contact your PolyAI representative. Create a workspace API key from the **API Keys** tab. See [API keys](https://docs.poly.ai/secrets/api-keys.md).

Use your region’s base URL. See [Getting started](https://docs.poly.ai/api-reference/introduction.md#pick-your-region) for the full list. Personal access tokens are region-specific: a token created in one region is rejected with a `401` in any other.

## Recommendations

A recommendation is something Wren found on a project that could be improved, with what happens, why, and where it stands.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://api.us.poly.ai/v1/accounts/acme-us/projects/acme-team-4/recommendations?nextStep=fix_ready,question" \
  -H "x-api-key: YOUR_API_KEY"
```

Each recommendation carries a `nextStep` saying what it is waiting for:

| `nextStep` | Meaning |
| - | - |
| `needs_attention` | Wren has identified it, and it is yours to act on |
| `question` | Wren has a question for you. The `questions` field holds it |
| `answered` | The question is answered and a fix is still to come |
| `fix_proposed` | A fix is proposed. The `proposedFix` field says what it changes |
| `fix_ready` | A fix is proposed and has been checked |

`nextStep` is `null` once a recommendation is closed.

A few things worth knowing:

* **The list shows open recommendations by default.** Pass `all=true` or a `status` filter to include closed ones.
* **Recommendations saved for later are left out by default.** Pass `saved=true` to list only those, or `all=true` to include everything.
* **Snippets are illustrative.** `conversationSnippet` and `changeSnippet` are short examples written to show the pattern. They are not transcripts of real calls.
* **Answers appear on a single recommendation only.** While `nextStep` is `answered`, [Get a recommendation](https://docs.poly.ai/api-reference/wren/endpoint/recommendations/get-recommendation.md) returns each question with its answer. The list does not.
* **The API is read-only.** Dismissing, commenting on, answering and approving a recommendation are done in Agent Studio.

## Turns

Sending a turn starts a Wren run and streams it back as server-sent events. Runs can take many minutes, so keep the connection open and set your client’s read timeout accordingly.

The [Wren API guide](https://docs.poly.ai/wren/api.md) covers modes, answering questions, continuing a conversation, and using Wren from your own agents.

## Error responses

| Status | Description |
| - | - |
| 400 | A parameter or the request body is invalid |
| 401 | Missing or invalid key, the wrong kind of key for the endpoint, or a key from another region |
| 403 | The key has no access to the project, or the feature is not enabled for the account |
| 404 | No such recommendation |
| 409 | A run is already in progress on the session (turns only) |
| 500 | Something went wrong on our side |

Errors come back as JSON with an `error` message:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": "Invalid list query",
  "invalid": ["nextStep"]
}
```

## Pagination

The list returns `limit` recommendations at a time, 20 by default and at most 100. When there are more, `pagination.hasMore` is `true` and `pagination.nextOffset` is the `offset` to pass for the next page.
