# Unlock the fix

Unlocks the fix of an issue and returns it: a prompt written for your coding agent, to paste into Cursor, Claude Code or Lovable.

```
POST https://api.rustine.io/v1/issues/{issue_id}/fix
```

OAuth permission: `fixes:unlock` · an API key has them all

> The first call for an issue **uses one fix** from your plan (`charged: true`); later calls are free. Send an [`Idempotency-Key`](https://docs.rustine.io/en/idempotency): a replayed call never charges twice. Rustine never edits your code.

## Path parameters

- `issue_id` (string, required) Issue id.

## Headers

- `Idempotency-Key` (string) A unique key (1 to 255 printable characters, a UUID is fine) to retry this request safely: the first response is replayed for 24 hours; the same key with another request answers 409 `idempotency_conflict`.

## Response (200 OK)

- `object` (string, required)
- `issue_id` (string, required) The issue.
- `prompt` (string, required) The fix as instructions for a coding agent.
- `ai_fix` (string | null, required) A patch written by Rustine, if any.
- `charged` (boolean, required) True when this call unlocked the fix and consumed one; false when it was already unlocked.
- `fixes_left` (integer, required) Fixes left this period after this call (quota plus pack credits).

## Examples

### curl

```bash
# The key stays in a variable, never in the address
curl https://api.rustine.io/v1/issues/2a4c6e8f-0b1d-4f3a-9c5e-7a9b1c3d5e7f/fix \
  -X POST \
  -H "Authorization: Bearer $RUSTINE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

### Node

```js
const res = await fetch(
  "https://api.rustine.io/v1/issues/2a4c6e8f-0b1d-4f3a-9c5e-7a9b1c3d5e7f/fix",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.RUSTINE_API_KEY}`,
      "Idempotency-Key": crypto.randomUUID(),
    },
  },
)
const fix = await res.json()
```

### Python

```python
import os
import uuid

import requests

fix = requests.post(
    "https://api.rustine.io/v1/issues/2a4c6e8f-0b1d-4f3a-9c5e-7a9b1c3d5e7f/fix",
    headers={
        "Authorization": f"Bearer {os.environ['RUSTINE_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
).json()
```

### Response: 200 OK

```json
{
  "object": "fix",
  "issue_id": "2a4c6e8f-0b1d-4f3a-9c5e-7a9b1c3d5e7f",
  "prompt": "Your .env file is served publicly at https://app.example.com/.env.\n1. Remove .env from the public directory of the build…\n2. Rotate every secret it contained…",
  "ai_fix": null,
  "charged": true,
  "fixes_left": 82
}
```

## Errors

| Status | error.code | What happens |
| --- | --- | --- |
| 400 | `idempotency_key_invalid` | The `Idempotency-Key` header must be 1 to 255 printable characters. |
| 401 | `authentication_required` | No key in the request. Pass it in the `Authorization: Bearer rst_…` header, never in the address. |
| 401 | `invalid_api_key` | The key or OAuth token is wrong, revoked or expired. Check it is copied in full, or create a new key. |
| 402 | `api_plan_required` | The workspace is on the Free plan. The API comes with Pro, or on a 14-day trial with Solo. |
| 402 | `api_trial_ended` | Solo's 14-day trial is over. Move to Pro: your keys work again at once. |
| 402 | `fix_quota_exceeded` | This period's fixes are used up, and no pack credit is left. A fix already unlocked stays readable. |
| 402 | `project_paused` | The project is paused: your plan covers fewer projects than your workspace has. Its issues stay readable, but nothing new runs. |
| 403 | `scope_missing` | The OAuth token lacks the permission this route needs (shown on its page). Reconnect the agent to grant it. An API key has every permission. |
| 404 | `resource_not_found` | Nothing with this id in the key's workspace. An object of another workspace answers the same: its existence is never revealed. |
| 409 | `proof_required` | The site must first be proved yours (full audit, fix, marking). Prove it in the app: DNS, file or meta tag. |
| 409 | `idempotency_conflict` | This `Idempotency-Key` was already used for another request (method, path or body). A new action takes a new key. |
| 409 | `idempotency_in_progress` | A request with this `Idempotency-Key` is still running. Retry in a moment. |
| 429 | `rate_limited` | Too many requests for this key (120 per minute). Wait `Retry-After` seconds. |
| 500 | `internal_error` | An error on our side, reported automatically. Retry later; give the `Request-Id` to support if it comes back. |
| 503 | `service_unavailable` | Rustine is unavailable for a moment. Retry with the same `Idempotency-Key`. |

https://docs.rustine.io/en/api/errors
