# Link a Polymarket wallet

Source: https://langbot.ai/docs/api/bots/link-wallet

`POST /v1/bots/{bot_id}/wallets`

Attach a Polygon address's Polymarket fills from Langbot's own on-chain recording. Read-only: no key is involved, and the address's trades are public.

**Auth.** An account token (`Authorization: Bearer lb_…`) or a signed-in web session. A report-only token (`lbr_…`) is refused here with `403 scope_denied`.

**Limits.** Counts against your plan's API requests (60, 600 or 3,000 a minute on Free, Builder and Standard).

## Parameters

### Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `bot_id` | string | yes | The bot id (`bot_…`); it must list `polymarket`. |

### Body

| Name | Type | Required | Description |
|---|---|---|---|
| `chain` | string | no | `polygon`. Default `polygon`. |
| `address` | string | yes | The address that holds the positions (`0x` + 40 hex): the wallet your Polymarket profile shows, not a signing key. Mixed case must be a valid checksum. |
| `backfill_hours` | integer | no | How far back to attach fills from, in hours (at most 6 days). 0 to 144. Default `24`. |

## Request

**curl**

```bash
curl -X POST "https://api.langbot.ai/v1/bots/bot_01M6G72RFQRQ8JGNG8T1447GGP/wallets" \
  -H "Authorization: Bearer $LANGBOT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"chain": "polygon", "address": "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", "backfill_hours": 24}'
```

**Python**

```python
from langbot import LangbotClient

async with LangbotClient() as lb:  # reads LANGBOT_API_TOKEN
    w = await lb.bots.link_wallet("bot_01M6G72RFQRQ8JGNG8T1447GGP", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
```

**TypeScript**

```ts
import { LangbotClient } from "@langbotai/sdk";

const lb = new LangbotClient(); // reads LANGBOT_API_TOKEN
const w = await lb.bots.linkWallet("bot_01M6G72RFQRQ8JGNG8T1447GGP", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed");
```

## Response

`201 Created`

```json
{
  "id": "bw_01M6G72VJ4YE3V9SPJRKD7NK0W",
  "chain": "polygon",
  "address": "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed",
  "linked_at": 1793693150788,
  "backfill_from": 1793606750788,
  "backfill_done_at": null
}
```

Fills appear within a minute of being recorded on chain, as fills with `source: "chain"`; the backfill runs in the background (`backfill_done_at`). While a wallet is linked, Polymarket fills your bot reports itself are kept but do not move P&L (`applied: false`), so nothing is counted twice. On-chain fills carry no fee (`fee: null`).

## Errors

| Status | `code` | When |
|---|---|---|
| 404 | `not_found` | No bot with that id on your account (or it was deleted). |
| 409 | `conflict` | The address is already linked on your account, or the bot has 5 wallets. |
| 401 | `auth_required` | No token was sent. |
| 401 | `token_invalid` | The token was not recognised (mistyped, revoked or expired). |
| 422 | `validation_error` | A parameter failed validation; `detail[].loc` names it. |
| 429 | `rate_limited` | Over your request budget; wait `Retry-After` seconds. |

Every error body is `{"detail": …, "code": "…"}`; branch on `code`. All codes: [Errors](https://langbot.ai/docs/api#errors).
