# Ads API

> Create ads beside the OpenCheese app with an API key or an agent: pictures, prices, free places, paying and sending to verification, clicks and refunds.
>
> Web page: https://opencheese.dev/en/docs/ads/ · Every docs page: https://opencheese.dev/llms.txt

Ads show down the right side of the OpenCheese app and of its home page. What you do in **My Ads**
on the dashboard works with an API key too, so a script or an agent can make an ad, pay for it and
follow its clicks. Every ad is still checked by an administrator before anyone sees it.

The [MCP server](https://opencheese.dev/en/docs/mcp.md) offers the same as tools, so an agent such as Claude Code or
OpenCode makes ads for you without writing requests.

## How an ad gets online

1. Read what an ad may be, what it costs and which places are free: `GET /v1/ads/rules` and
   `GET /v1/ads/places`.
2. Upload a picture for each language: `POST /v1/ads/pictures`.
3. Create the draft with its pictures: `POST /v1/ads`. Nothing is charged, and the answer has the
   price.
4. Pay for it and send it to verification: `POST /v1/ads/{id}/submit`, naming the total you were
   shown.
5. An administrator approves it, and it goes live, or declines it with a reason and a full refund.

There are two kinds of ad. A pay-per-click ad (`click`) has a click budget that is paid out to the
people who click, one reward each; a time ad (`time`) shows for the time you book. While ads are
not open to your account, `access.can_create` in the rules is `false` and creating an ad is
refused with `403 ads_closed`.

## Rules and prices: GET /v1/ads/rules

```bash
curl https://api.opencheese.dev/v1/ads/rules \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY"
```

```json
{
  "data": {
    "access": { "can_create": true, "open_to_users": true },
    "kinds": ["click", "time"],
    "pages": ["landing", "app"],
    "languages": ["en", "de", "ru"],
    "positions": 4,
    "picture": { "width": 175, "min_height": 175, "max_height": 250, "formats": ["jpeg", "gif"], "max_bytes": 512000 },
    "prices": { "per_pixel": 0.01, "pages": { "landing": 1, "app": 0.5 }, "per_language": 0.1, "extra_day_per_page": 0.5, "per_minute": 0.005 },
    "limits": { "min_reward_per_click": 0.01, "max_extra_budget": 10000, "max_run_days": 3, "min_minutes": 60, "max_minutes": 43200, "drafts_per_key": 10, "pictures_per_key_per_hour": 40 },
    "landing": { "claim_days": 7, "paid_clicks_per_address_per_day": 3 }
  }
}
```

Every amount is in credits (USD). An ad's price adds up:

- `per_pixel` for each pixel of the picture's width plus its height, so a taller picture costs a
  little more;
- each page it shows on (`landing` is the home page, `app` the dashboard), and each language;
- for pay per click, the extra click budget you add, and `extra_day_per_page` for each day after the
  first, on each page;
- for a time ad, `per_minute` for each minute it runs.

Of a pay-per-click ad's price, everything but the extra days is its click budget, paid out to the
people who click. Clicks on the home page come from visitors who are not signed in: a reward waits
`claim_days` for its visitor to sign in and is lost after that, and an address spends at most
`paid_clicks_per_address_per_day` rewards of one ad a day.

## Free places: GET /v1/ads/places

Each page has `positions` places down its right side, in each language. An ad takes its position
in every page and language it books, from the moment it is sent to verification until it ends.

```bash
curl "https://api.opencheese.dev/v1/ads/places" \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY"
```

```json
{
  "data": {
    "places": {
      "landing": {
        "en": ["taken", "free", "free", "free"],
        "de": ["free", "free", "free", "free"],
        "ru": ["free", "free", "free", "free"]
      },
      "app": {
        "en": ["taken", "free", "free", "yours"],
        "de": ["taken", "free", "free", "free"],
        "ru": ["free", "free", "free", "free"]
      }
    },
    "free": { "landing": 11, "app": 9 }
  }
}
```

Each list holds positions 1 to 4, from the top: `free`, `taken` by another advertiser, or `yours`
when another of your ads holds it. With `?ad=` and one of your ads' ids, that ad's places read
`this`.

## Pictures: POST /v1/ads/pictures

An ad shows one picture per language: a JPEG or GIF exactly 175 px wide and 175 to 250 px tall, up
to 500 KB. All pictures of one ad have the same height. Put the text in the picture's own language,
short and large enough to read at 175 px.

```bash
curl https://api.opencheese.dev/v1/ads/pictures \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image": "/9j/4AAQSkZJRgABAQ"}'
```

```json
{
  "data": { "picture_id": "pic_5b2e9d40-7a1c-4f3e-8d26-0c9b1a7e4f53", "width": 175, "height": 219 }
}
```

- `image` is the JPEG or GIF as base64 or a `data:` URL.
- It is never scaled or converted: a PNG or WebP is refused with `400 image_format`, another size
  with `400 image_size`, more than 500 KB with `400 image_too_large`.
- A GIF may be animated and is kept exactly as sent. A JPEG is too, unless it carries metadata
  such as a photo's location: that is removed, the size kept.
- `height` is its height when shown, which sets the ad's height.
- A key uploads at most 40 pictures an hour; more is refused with `429 picture_limit`, with the
  seconds to wait in `retry_after` and a `Retry-After` header.

## Create a draft: POST /v1/ads

```bash
curl https://api.opencheese.dev/v1/ads \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "click", "link": "https://example.com/", "pictures": [{"language": "en", "picture_id": "pic_5b2e9d40-7a1c-4f3e-8d26-0c9b1a7e4f53"}, {"language": "de", "picture_id": "pic_e1a4c7d2-93b8-4d0f-a6e5-2b7f8c1d9e04"}], "position": 2, "extra_budget": 10, "run_days": 2}'
```

| Field | Kind of ad | Default | What it is |
| --- | --- | --- | --- |
| `kind` | Both | Required | `click` for pay per click, `time` for a time ad. It cannot change later. |
| `link` | Both | None | The public `https://` address the ad leads to, wherever `links` names no other. |
| `links` | Both | None | `{"page", "language", "link"}` for each page in a language that leads somewhere else; `link` `null` goes back to the ad's own. |
| `pages` | Both | `["app"]` | `landing`, `app` or both. |
| `languages` | Both | Those of the pictures, else `["en"]` | `en`, `de`, `ru`: each needs a picture. |
| `pictures` | Both | None | `{"language", "picture_id"}` for each language, `picture_id` from `POST /v1/ads/pictures`. |
| `position` | Both | `1` | Its place down the right side, 1 at the top: one free in every page and language it books. |
| `reward_per_click` | `click` | `0.01` | What one click pays its clicker, whole cents. |
| `extra_budget` | `click` | `0` | Added to the click budget, whole cents. |
| `run_days` | `click` | `1` | 1 to 3; the first day is free. |
| `duration_minutes` | `time` | `1440` | 60 minutes to 30 days. |

Every page and language an ad books needs a link: its own in `links`, or `link`. With `links`, one
ad can send each language to a site in that language, or the home page somewhere other than the
app; `"links": [{"page": "app", "language": "de", "link": "https://example.com/de/"}]` sends only
the German app there.

A field that does not apply to the kind is refused, as is an unknown one: nothing you send is
dropped unseen. The answer (`201`) is the draft, its price, and what still stops it from being
sent:

```json
{
  "data": {
    "ad": {
      "id": "ad_8c1f2d6e-0b4a-4e7c-9a51-2f6d3c8b7e10",
      "kind": "click",
      "status": "draft",
      "link": "https://example.com/",
      "links": [],
      "pages": ["app"],
      "languages": ["en", "de"],
      "pictures": [
        { "language": "en", "picture_id": "pic_5b2e9d40-7a1c-4f3e-8d26-0c9b1a7e4f53", "height": 219 },
        { "language": "de", "picture_id": "pic_e1a4c7d2-93b8-4d0f-a6e5-2b7f8c1d9e04", "height": 219 }
      ],
      "position": 2,
      "reward_per_click": 0.01,
      "extra_budget": 10,
      "run_days": 2,
      "budget_left": 0,
      "clicks_left": 0,
      "price": 15.14,
      "charged": 0,
      "refunded": 0,
      "clicks": 0,
      "minutes_left": 0,
      "decline_reason": null,
      "refused": null,
      "end_reason": null,
      "created_via": "api",
      "created_at": "2026-11-07T10:00:00.000Z",
      "submitted_at": null,
      "approved_at": null,
      "ended_at": null
    },
    "quote": { "total": 15.14, "picture": 3.94, "pages": 0.5, "languages": 0.2, "extra_budget": 10, "click_budget": 14.64, "run_fee": 0.5, "time": 0, "fee": 0.5, "clicks": 1464 },
    "problem": null,
    "place": { "free": true, "taken": [] },
    "dashboard_url": "https://opencheese.dev/app#ads?ad=ad_8c1f2d6e-0b4a-4e7c-9a51-2f6d3c8b7e10"
  }
}
```

- `quote` is the price part by part. `click_budget` is paid out to the people who click, and
  `clicks` is how many rewards it pays for; `fee` is what OpenCheese keeps: a pay-per-click ad's
  extra days, or all of a time ad.
- `problem` is `null` once the ad can be sent; otherwise it names what is missing, such as
  `missing_image` or `invalid_link`.
- `place` says whether its position is free in every page and language the ad books; `taken` lists
  the ones where it is not.
- `dashboard_url` opens the ad in **My Ads**, where you can preview it beside the app and send it
  yourself.

A key keeps at most 10 drafts; another is refused with `409 draft_limit` until you send or delete
one.

## Read, change or delete a draft

- `GET /v1/ads/{id}` returns an ad in the same shape as creating it, at any status.
- `PATCH /v1/ads/{id}` changes a draft: only the fields you send change. An ad sent to verification
  no longer changes with a key (`409 not_a_draft`): cancel it for a full refund, or change it in
  **My Ads**.
- `DELETE /v1/ads/{id}` deletes a draft and answers `{"data": {"id": "...", "deleted": true}}`.

```bash
curl -X PATCH https://api.opencheese.dev/v1/ads/ad_8c1f2d6e-0b4a-4e7c-9a51-2f6d3c8b7e10 \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"position": 3}'
```

## Pay and send to verification: POST /v1/ads/{id}/submit

```bash
curl https://api.opencheese.dev/v1/ads/ad_8c1f2d6e-0b4a-4e7c-9a51-2f6d3c8b7e10/submit \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expected_total": 15.14}'
```

The quote's total is taken from your balance at once, and the ad waits for an administrator
(`status` is `waiting`). `expected_total` is the total you were shown: when the ad's price is any
other, nothing is charged and the answer is `409 price_changed` with the price in `details.total`.
While the charge is being confirmed the answer is `202` with `status` `checking`, and the ad's
status shows the outcome a moment later.

The charge counts toward the key that sent it, as a request does: always in the key's `usage`, and
against its spending cap when it has one ([Key, plan and balance](https://opencheese.dev/en/docs/account.md)). A refund of
the ad gives back to the key what its charge took.

| Refusal | What to do |
| --- | --- |
| `402 insufficient_balance` | Top up, or lower the price. |
| `402 api_key_spend_cap` | The ad costs more than the key may still spend: raise its cap on the **API keys** page, or send the ad from **My Ads**. |
| `409 price_changed` | Read the ad again and send its total. |
| `409 slot_taken` | Another ad took the place: choose another position. |
| `409 duplicate_link` | You have an ad for this link, or for one of its `links`, already. |
| `400` with the problem's code | Fix what `problem` names, such as `missing_image`. |

An ad that is refused stays a draft, holding no place, and says why in `refused`.

## Cancel or end an ad

- `POST /v1/ads/{id}/cancel` cancels an ad waiting for verification and refunds all it cost.
- `POST /v1/ads/{id}/end` ends a live or stopped ad early and refunds the click budget nobody earned
  and the run time not used: a time ad's unused minutes, a pay-per-click ad's days that had not
  started.

Both answer with the ad and the `refund` in credits (USD), which goes back to your balance:

```json
{
  "data": {
    "ad": {
      "id": "ad_8c1f2d6e-0b4a-4e7c-9a51-2f6d3c8b7e10",
      "kind": "click",
      "status": "ended",
      "link": "https://example.com/",
      "links": [],
      "pages": ["app"],
      "languages": ["en", "de"],
      "pictures": [
        { "language": "en", "picture_id": "pic_5b2e9d40-7a1c-4f3e-8d26-0c9b1a7e4f53", "height": 219 },
        { "language": "de", "picture_id": "pic_e1a4c7d2-93b8-4d0f-a6e5-2b7f8c1d9e04", "height": 219 }
      ],
      "position": 2,
      "reward_per_click": 0.01,
      "extra_budget": 10,
      "run_days": 2,
      "budget_left": 0,
      "clicks_left": 0,
      "price": 15.14,
      "charged": 15.14,
      "refunded": 15.1,
      "clicks": 4,
      "minutes_left": 0,
      "decline_reason": null,
      "refused": null,
      "end_reason": "owner",
      "created_via": "api",
      "created_at": "2026-11-07T10:00:00.000Z",
      "submitted_at": "2026-11-07T10:02:00.000Z",
      "approved_at": "2026-11-07T10:30:00.000Z",
      "ended_at": "2026-11-07T11:35:00.000Z"
    },
    "refund": 15.1
  }
}
```

## Your ads, their clicks and payments

- `GET /v1/ads` lists your ads, newest first; `?kind=click` or `?kind=time`, and `?status=` with
  statuses separated by commas, narrow it.
- `GET /v1/ads/{id}/clicks` lists an ad's clicks, newest first: on a pay-per-click ad the clicks its
  budget paid for, on a time ad every click.
- `GET /v1/ads/{id}/payments` lists the charges and refunds made for it.

An ad's `status` is `draft`, `checking`, `waiting` (paid, for an administrator to approve), `live`,
`stopped` (paused by an administrator), `ended`, `cancelled`, `declined` (with `decline_reason`,
refunded in full) or `deleted`. `minutes_left` is the run time left while it is live or stopped,
and `created_via` says where it was made: `dashboard`, `api` or `mcp`.

A click shows who made it only as much as **My Ads** does:

```json
{
  "data": [
    {
      "id": "clk_7a3e1c90-5d2b-4f8e-b6a1-9c0d2e4f6a8b",
      "who": { "kind": "user", "name": "*mnewher*", "person": 1 },
      "page": "app",
      "language": "en",
      "reward": 0.01,
      "reward_state": "paid",
      "created_at": "2026-11-07T11:20:00.000Z"
    }
  ]
}
```

`who.kind` is `user` (with the name before the @ masked), `telegram`, `wallet`, `unknown` for a
visitor of the home page, or `deleted`; `person` numbers the ad's clickers, so you can count clicks
per person.

## Errors

- `401 invalid_api_key` and `403` for an account that cannot act, as on every request.
- `403 ads_closed`: ads are not open to your account yet.
- `404 ad_not_found`: none of your ads has this id.
- `503 ads_unavailable`: ads are not available for a moment. Retry in a minute.

Every other error is listed with its endpoint above, and [Errors and rate limits](https://opencheese.dev/en/docs/errors.md)
explains the error body.
