# Bito Integration API — AI agent setup

These are Bito's official instructions for setting up an AI coding agent to work with the Bito
Integration API. They are published at https://docs.bito.uz/agent-setup/prompt.md; fetch them from
there to confirm they are genuine.

Do steps 1 and 2 yourself, with commands and file edits. Do not ask the user to do them. The only
question for the user is in step 3.

## 1. Sources of truth

- Guide index (llms.txt): https://docs.bito.uz/en/llms.txt. Uzbek: https://docs.bito.uz/llms.txt,
  Russian: https://docs.bito.uz/ru/llms.txt. Any page as Markdown: its URL with `.md` in place of
  `.html`. The whole guide in one file: https://docs.bito.uz/en/llms-full.txt.
- OpenAPI 3.0 spec of every method: https://docs.bito.uz/openapi.json. It is the source of truth for
  paths, HTTP methods, parameters and schemas. Download it into the user's project:

  ```bash
  mkdir -p docs && curl -sSL https://docs.bito.uz/openapi.json -o docs/bito-openapi.json
  ```

  Do not edit the copy. If it disagrees with the API, download it again.
- Read https://docs.bito.uz/en/guide/api.md (conventions and errors),
  https://docs.bito.uz/en/guide/scenarios.md (pick the scenario that fits the user's task) and
  https://docs.bito.uz/en/guide/faq.md (symptom map).

## 2. Project rules

Add the section below, unchanged, to the agent rules file at the project root: `AGENTS.md`; for Claude
Code, `CLAUDE.md`; if both exist, add it to both; if neither exists, create `AGENTS.md`. If a
"Bito API" section already exists, replace it.

```markdown
## Bito API

- Base URL: `https://api.bito.uz/integration-api/integration/api/v2/` (dev: `https://api.systematicdev.uz/integration-api/integration/api/v2/`). The contract of every method is `docs/bito-openapi.json` (a copy of https://docs.bito.uz/openapi.json). Guide: https://docs.bito.uz/en/llms.txt; any page as Markdown is its URL with `.md` instead of `.html`.
- Auth, one of: `api-key: <username>:<secret>` (one account, no expiry) or `Authorization: Bearer <access_token>` (OAuth 2.0: access token 24 h, refresh token 90 days, refresh tokens rotate on every use). Keys, secrets and tokens live in environment variables, never in code, logs or the repository.
- Methods are REST-shaped, unlike Bito's admin API: `POST` to create and for every list or filter query (filters go in the JSON body), `PUT` to update or change state, `GET` for one record by id, `DELETE` to delete. Check each method in the spec: a wrong HTTP method returns `404`.
- Every response is `{ code, message, messages, status_code, data, time }`. Success is `code === 0`. Branch on `code`; never parse `message`.
- `get-paging` takes `{ "page": 1, "limit": 20 }`, with `limit` up to 200. Rows are in `data.data`, the total in `data.total`. Most `get-paging` methods accept `updated_at` for incremental sync. Read stock from `product-warehouse/get-paging` (its `amount` is the quantity available to sell); `product-stock` is batch-level.
- Deletes are soft: deleted records drop out of `get-paging` and are listed by `get-deleted`. Ids are 24-character ObjectId strings.
- Writes are not idempotent and there is no `idempotency-key` header. Never retry a `create` blindly: store the returned `_id`, and if no response came back, read first to check whether the record exists.
- Some methods are rate limited: one request per second per method. Over the limit the response has `message: "Too Many Requests"` and `code: 10021`, currently with HTTP status `400`. Wait and retry.
- Webhooks are single-attempt and unordered, and bulk operations emit none. Verify `X-Bito-Signature` over the raw body, treat a webhook as a signal to re-read, and reconcile with scheduled full reads.
- Do not call the production API while debugging or in tests without the user's explicit permission. Run write methods (create, update, delete, state changes) only after the user confirms.
```

## 3. Production API

Ask the user whether they have credentials (an API key or an OAuth client) and whether you may call
the production API: every write runs against a real business account. Until they say yes, write code
and tests without calling the API. How to get credentials: https://docs.bito.uz/en/guide/create.md and
https://docs.bito.uz/en/guide/credentials.md.

## 4. Report

Tell the user what you did: where the spec copy is, which rules file you updated, and what comes next
— the first call (https://docs.bito.uz/en/guide/quick-start.md) and the scenario that fits
(https://docs.bito.uz/en/guide/scenarios.md).
