# Kody Pocztowe API (Polish zip codes) - full description > HTTP API and MCP server for Polish postal codes (kody pocztowe) from the official list of Poczta Polska S.A. (spis PNA), completed with streets and localities from the GUGiK address register (PRG). 50 free requests per day per client IP address; more with a prepaid request package bought with an x402 payment (USDC on Base) or a RapidAPI plan. Base URL: `https://kodpocztowy.intami.pl`. OpenAPI 3 specification: `https://kodpocztowy.intami.pl/open-api.yaml`. Short summary: `https://kodpocztowy.intami.pl/llms.txt`. MCP server: `https://kodpocztowy.intami.pl/mcp`. ## Access, limits and payment - Free: without a key every client gets 50 requests per day (the day is a UTC day). The client is the IP address, for IPv6 the /64 prefix. The REST API and the MCP tools share this counter. No sign-up is needed. - What is counted (for the free limit and for packages alike): an answer with a result (`2xx`) and a lookup that found nothing (`404`; in MCP a lookup with `count` 0). Not counted: invalid parameters (`400`; in MCP a tool error), server errors (`5xx`), the `404` of the router (a path that does not exist), `401`, `402`, `405`, `429`, CORS preflights (`OPTIONS`), MCP `initialize` and `tools/list`, `GET /x402/packages`. - Technical limit: 120 requests per minute per client (per RapidAPI user for requests through RapidAPI), with or without a key. Over it: `429` with `Retry-After: 60` (in MCP the tool error `technical rate limit`). - Over the free limit (a key whose prepaid requests are used up falls back to the free daily limit of the client), a lookup answers `402` with JSON `{"error":"payment_required","message":...,"packages":[{"id","requests","price","buy_url"}],"packages_url":...,"upgrade_url":...,"limits_url":...}`. This `402` is not an x402 offer: single lookups are not sold, only packages. - Request packages, bought with an x402 payment in USDC on Base (the price includes the network fee; packages have no daily limit and do not expire): - `pro`: 30000 requests for 5 USDC, - `mega`: 900000 requests for 12 USDC. `GET /x402/packages` returns the current list: `{"packages":[{"id":"pro","requests":30000,"price":"5 USDC on Base","buy_url":"https://kodpocztowy.intami.pl/x402/packages/pro"},...],"upgrade_url":...}`. - API key: a purchase returns a key starting with `kp_`. Send it in the `X-API-Key` header (MCP: the `api_key` argument of the lookup tools or the `X-API-Key` header of the client). Each counted request uses one prepaid request; answers carry `X-Requests-Remaining` (MCP: `_meta["requests_remaining"]`). An invalid or disabled key is answered `401` (`invalid credentials`; in MCP a tool error). - Paid RapidAPI plans are an alternative: `https://rapidapi.com/intami-intami-default/api/polish-zip-codes1/pricing` (the `upgrade_url` of the `402` answers). Requests made through RapidAPI use the RapidAPI gateway and its keys, not `X-API-Key`. ### Buying a package with x402 (HTTP) `POST /x402/packages/{id}` (`id` = `pro` or `mega`): 1. Without a `PAYMENT-SIGNATURE` header the answer is `402` with the x402 v2 payment requirements in the body and, base64-encoded, in the `PAYMENT-REQUIRED` header (`accepts`: scheme `exact`, USDC on Base, amount, `payTo`). 2. Sign an EIP-3009 USDC transfer authorization for these requirements (no ETH needed, the facilitator pays the gas) and repeat the same request with the base64-encoded x402 payment payload in `PAYMENT-SIGNATURE`. The `validBefore` of the authorization may be at most 1 hour ahead. 3. `200` with `{"api_key":"kp_...","package":"pro","requests_added":30000,"requests_remaining":30000}`, the settlement receipt in `PAYMENT-RESPONSE` and `X-Requests-Remaining`. - Send `X-API-Key` with the purchase to top up that key instead of getting a new one (then there is no `api_key` in the answer). - Optional `X-Payment-Claim`: a random secret of 16-128 printable ASCII characters without spaces chosen by the buyer. Repeating a settled purchase returns the key only to the same client IP address or to a request with the same claim; otherwise `409`. - `503` `payment pending; retry the same authorization, do not create a new payment`: repeat with the SAME `PAYMENT-SIGNATURE`; do not sign a new one. A repeated settled payment returns the same result without paying again. - Other answers: `400` invalid payment, header or claim (nothing is charged), also for callers that are not metered (unlimited key, RapidAPI); `402` with `error` `invalid_payment` and `invalid_reason` when the facilitator rejects the payment; `404` unknown package; `409` the authorization was used for another package or account, by another client, or was not settled. ### Buying a package in a browser wallet `https://kodpocztowy.intami.pl/wallet.html?package=pro` (or `package=mega`) buys a package with a browser wallet such as MetaMask: the wallet only signs the USDC transfer authorization and the page shows the new API key. `https://kodpocztowy.intami.pl/wallet.html?package=pro#api_key=` tops up an existing key (the fragment is not sent to the server). This is the way for a human user or an agent that cannot sign x402 payments itself. ## Common rules of the REST API - Response formats chosen by the `Accept` header: `application/json` (default, also for `*/*`), `application/xml` (every endpoint), `text/plain` (zip code entries: one tab-separated line per entry; lists: one zip code per line), `text/html` (zip code entries only: `/{zipCode}` and the lookup by address). `/validate` answers JSON or XML. An `Accept` header without any supported type gives `500` (not counted). - Names of towns, streets and districts are compared case-insensitively, also for Polish letters (`łódź` = `ŁÓDŹ` = `Łódź`), ignoring extra spaces and quotes. Use the Polish spelling with diacritics (`Wrocław`, `Kraków`, `Gdańsk`) and URL-encode spaces (`%20`) and, if your client does not do it, the Polish letters. - If several towns share a name, the zip codes of all of them are returned; localities with the same name in different communes are not told apart. - Nothing found: `404` with an empty list (`[]` in JSON), also for a blank city, street or district. It is counted. - `un` query parameter of the lists of zip codes: `true` only zip codes of units (institutions such as post offices with an individual zip code), `false` without units, omitted: all. `1`/`on` and `0`/`off` are accepted; other values give `400`. - Responses: `Access-Control-Allow-Origin: *` (callable from browsers), `Cache-Control: no-store`. An optional `X-TraceId` request header (up to 128 printable ASCII characters) is copied to the response. ### Zip code entry fields `kod` (NN-NNN), `nazwa` (name of a unit with an individual zip code), `miejscowosc` (town), `ulica` (street), `numer` (house number of a unit), `gmina` (commune), `powiat` (county), `wojewodztwo` (voivodeship), `dzielnica` (city district), `numeracja` (house number ranges: `od` from, `do` to - empty means to the end of the street, `parzystosc` `PARZYSTE` even / `NIEPARZYSTE` odd / absent for all numbers; an empty `numeracja` covers every number). ## Endpoints ### Address of a zip code `GET /{zipCode}` - the entries of a zip code in the `NN-NNN` format (anything else gets the `404` of the router). `/api/{zipCode}` and `/kod/{zipCode}` are deprecated aliases. ``` curl -H 'Accept: application/json' 'https://kodpocztowy.intami.pl/01-111' ``` Answer (shortened): `[{"kod":"01-111","miejscowosc":"Warszawa","ulica":"Jana Olbrachta","gmina":"Warszawa-Wola","powiat":"Warszawa","wojewodztwo":"mazowieckie","dzielnica":"Wola","numeracja":[{"od":"1","do":"11a","parzystosc":"NIEPARZYSTE"},...]},...]` ### Zip codes of a town `GET /city/{city}[?un=true|false]` - a JSON array of zip codes, e.g. `https://kodpocztowy.intami.pl/city/Gdańsk` (`["80-001","80-003",...]`). ### Zip codes of a street `GET /city/{city}/street/{street}[?wildcard=true][&un=true|false]` - the zip codes of the street in the town; the street name as in the list of Poczta Polska, without `ul.`. `wildcard=true` matches every street of the town whose name contains the given text. - `https://kodpocztowy.intami.pl/city/Wrocław/street/Grodzka` - `["50-115","50-137"]` - `https://kodpocztowy.intami.pl/city/Warszawa/street/Mickiewicza?wildcard=true` ### Zip code of an address with a house number `GET /city/{city}/street/{street}/number/{number}[?district=]` - the zip code entries of the street whose numbering includes the house number (letter suffixes like `12b` are supported). The street may be given with or without a prefix (`ul.`, `al.`, `pl.`, `os.`), and its last words are enough (`Piłsudskiego` for `Marszałka Józefa Piłsudskiego`). Use `district` when the street exists in several districts (e.g. in Warszawa). Units are not included. ``` curl 'https://kodpocztowy.intami.pl/city/Szczecin/street/Piłsudskiego/number/40' curl 'https://kodpocztowy.intami.pl/city/Warszawa/street/Adama%20Mickiewicza/number/30?district=Żoliborz' ``` The first answers the entry with `"kod":"70-421"`, the second `"kod":"01-616"`. ### Zip codes of a city district `GET /city/{city}/district/{district}[?un=true|false]` - the district with or without the city name (`Krowodrza` or `Kraków-Krowodrza`), e.g. `https://kodpocztowy.intami.pl/city/Warszawa/district/Wola`, `https://kodpocztowy.intami.pl/city/Kraków/district/Krowodrza`. ### Validate the zip code of an address `POST /validate` with a JSON body (at most 64 KiB): `kod` (zip code to check, optional - without it the answer gives the correct codes), `miejscowosc` (town, required), `ulica` (street, optional for a town without streets), `numer` (house number; a flat number after `/` is ignored), `dzielnica` (district, optional). One call is one request. ``` curl -X POST -H 'Content-Type: application/json' -d '{"kod":"70-420","miejscowosc":"Szczecin","ulica":"al. Piłsudskiego","numer":"40"}' 'https://kodpocztowy.intami.pl/validate' ``` Answer: `{"poprawny":false,"kody":["70-421"],"dopasowania":[...],"uwagi":["dopasowano ulicę Marszałka Józefa Piłsudskiego","kod 70-420 nie pasuje do numeru 40; właściwy 70-421"]}`. `poprawny` is true when the address was found and `kod` (if given) is one of its codes; `dopasowania` are the matching entries (at most 50); `uwagi` are notes in Polish. An unknown address is not an error: `poprawny` false, no codes and a note. `400` for a body that is not JSON or without `miejscowosc`. ### Database information `GET /_info_` - `{"records":,"updated":"