# Authentication (/docs/authentication) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. API keys, environments, and what happens when a key is rejected. Every request to the API carries an API key in the `Authorization` header, with the `Bearer` scheme: ```http Authorization: Bearer sk_test_… ``` The key identifies an **environment**, and the environment decides which data the request can see. ## Environments [#environments] Every merchant has two environments, with separate data: | Environment | Key prefix | What it moves | |---|---|---| | Test | `sk_test_` | Nothing: the bank is simulated. See [Test mode](/docs/test-mode) | | Live | `sk_live_` | Real PIX payments | A test key only reaches the test environment, and a live key only the live one. There is no parameter to switch environments: the key decides. ## The key [#the-key] - It is shown **once**, when it is created. The platform stores only a hash of it, so a lost key cannot be recovered: create another. - It can be revoked at any time. Revoking is permanent. - Keep it on your server. Never send it to a browser or a mobile app, and never commit it to a repository. ## Getting a key [#getting-a-key] A key is created in the dashboard, in **API keys**, under the mode it is for. Give it a name, to tell your keys apart later, choose what it can do with charges, with refunds, with offers and with the balance, and copy it then: the dashboard shows it once. A key cannot create another key. Creating a key asks for your passkey again when you signed in more than 5 minutes ago. Revoking one never does. ## What a key can do [#what-a-key-can-do] A key does only what its **scopes** say. Every operation asks the key for one, and a key has the scopes it was created with. | Scope | What it allows | |---|---| | `charges:read` | Reading and listing charges, with `getCharge` and `listCharges` | | `charges:write` | Creating a charge, with `createCharge`. With a test key, also the operations that simulate the bank. See [Test mode](/docs/test-mode) | | `refunds:read` | Reading and listing refunds, with `getRefund` and `listRefunds` | | `refunds:write` | Asking for a refund, with `createRefund`. It is the only scope that moves money out. See [Refunds](/docs/refunds) | | `offers:read` | Reading and listing offers, with `getOffer` and `listOffers` | | `offers:write` | Putting an offer on sale and archiving it, with `createOffer` and `archiveOffer`. See [Offers](/docs/offers) | | `balance:read` | Reading the balance, with `getBalance`. See [Balance](/docs/balance) | - **Give a key only what its job needs.** A key that only answers questions needs the `read` scopes and nothing else. - **Writing does not include reading.** A key with `charges:write` alone creates a charge and cannot read it back: give it `charges:read` as well. - **A key only has the scopes it was created with.** A scope is never added to a key that exists: to do something else through the API, create another key in the dashboard. The list of keys shows what each one can do. - **A key is never created without a scope.** It would call no operation. - **A key created before every operation asked for a scope** has the scopes of what it did then: `charges:read`, `charges:write` and `refunds:read`. It has `refunds:write` only if it was created with it. - **An operation that arrives later asks for a scope that no earlier key has.** Offers and the balance came after the first keys: to use them, create a key with their scopes. - In the [OpenAPI contract](/openapi.yaml), each operation names its scope in its `security`. - Without the scope the answer is `403`, with the code `insufficient_scope`, and the `WWW-Authenticate` header names the scope that is missing. The key is valid: do not replace it for the other operations. - The scope is checked right after the key, before the request is read: a key without it gets the same `403` whatever else the request has wrong. ## When a key is rejected [#when-a-key-is-rejected] Without a valid key the answer is `401`, with the code `unauthorized`. - A missing, malformed, unknown or revoked key gets exactly the same answer. The API does not say which case it was. - The key is checked before anything else. Without a valid key the answer is `401` whether the route exists or not. - Check first that the key belongs to the environment you expect. ## Rate limits [#rate-limits] Requests are limited by API key and by IP address. Over the limit the answer is `429`, with the code `rate_limited`, and the `Retry-After` header says in how many seconds to try again. When you retry the creation of a charge or of a refund, send the same `Idempotency-Key`. # Balance (/docs/balance) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. What your sales left in the environment: what can be paid out, what is still pending, what a dispute holds and what is on its way out. The balance is what the paid charges left in the environment, after fees, refunds, disputes and payouts. It is never stored: it is the sum of the ledger at the moment you read it. ## Operations [#operations] | Operation in the contract | What it does | |---|---| | `getBalance` | Returns the four balances of the environment. Requires the `balance:read` scope | The route and the fields are in the [OpenAPI contract](/openapi.yaml), under this name. It is the same balance the dashboard shows in **Saldo**. ## The four balances [#the-four-balances] Every amount is an integer number of cents. | Field | What it is | |---|---| | `available_cents` | What can leave in a payout now: what was paid, minus the fees, the refunds, the payouts, what a dispute holds and what is still pending | | `pending_cents` | The part of the balance that cannot leave in a payout yet: what the charges paid less than the release period ago left | | `blocked_cents` | What the bank holds because a payer disputed the payment, until it decides: the amount of the charges in dispute | | `outgoing_cents` | What already left the balance and the bank has not confirmed yet: the refunds on their way to the payers and the payouts on their way to you | The four are read at the same instant: one is never from before an entry of the ledger and another from after it. ## The release period [#the-release-period] What a paid charge leaves is yours at once, and it can be paid out only after the release period of your account. - **Every account starts with a release period of 2 days**, counted from the moment each charge was paid. The period is a setting of your account. - **A paid charge enters `pending_cents` first.** When its period ends, its amount moves to `available_cents` by itself, charge by charge. No event tells you: read the balance again. - **`available_cents` plus `pending_cents` is what you have.** A refund and a dispute take from the two together, so a charge can be refunded before its period ends. - **Only a charge that is still `paid` counts.** A `refunded` or `disputed` charge is not pending, and neither is one with a refund on its way: its amount already left the balance. - **`pending_cents` is never more than what the balance has.** When a refund or a dispute of an older charge takes part of it, it shrinks, and `available_cents` stays at zero until what is left is released. ## What changes it [#what-changes-it] | What happens | `available_cents` plus `pending_cents` | `blocked_cents` | `outgoing_cents` | |---|---|---|---| | A charge becomes `paid` | Grows by the amount, minus the fee, in `pending_cents` | | | | The release period of a charge ends | Stays the same: the amount moves from `pending_cents` to `available_cents` | | | | A refund is asked for | Shrinks by what the refund takes | | Grows by the amount of the refund | | The refund reaches the payer | | | Shrinks by the amount of the refund | | The bank does not make the refund | Grows back | | Shrinks by the amount of the refund | | The payer disputes a charge | Shrinks by what the dispute takes | Grows by the amount of the charge | | | The bank refuses the dispute | Grows back | Shrinks by the amount of the charge | | | The bank accepts the dispute | | Shrinks by the amount of the charge | | - What a refund or a dispute takes from the balance depends on the fee rule of your account. See [The amount](/docs/refunds#the-amount) and [Disputes](/docs/disputes). - A payout, asked for in the dashboard, moves its amount from `available_cents` to `outgoing_cents` until the bank confirms it. A payout never takes from `pending_cents`. - **`available_cents` can be negative.** A dispute takes its amount even when you already withdrew it, and the next sales cover it. - **Read the balance again instead of keeping it.** A `refund.created` or a `charge.paid` webhook tells you it changed. See [Webhooks](/docs/webhooks). ## What a key needs [#what-a-key-needs] - **`balance:read`.** No other scope includes it: a key that creates and reads charges does not read the balance. See [What a key can do](/docs/authentication#what-a-key-can-do). - **A key created before the balance was in the API does not have it.** A scope is never added to a key that exists: create another key in the dashboard. - Without the scope the answer is `403` with the `insufficient_scope` code. ## What is not in the API [#what-is-not-in-the-api] The statement, with each entry that changed the balance, and the payouts are in the dashboard, under **Saldo**. A payout asks for your passkey, and an API key cannot ask for one. ## The balance of another environment [#the-balance-of-another-environment] The balance is always the one of the environment of your key. There is no parameter to read another: a test key reads the test balance, and a live key the live one. # Charges (/docs/charges) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. A PIX payment to receive: how to create it, follow its state and retry safely. A charge is a PIX payment to receive: an amount, a PIX code for the payer and an expiration. You create the charge, hand the code to the payer, and follow its state until it is paid or it expires. ## Operations [#operations] | Operation in the contract | What it does | |---|---| | `createCharge` | Creates the charge and its PIX code. Requires `Idempotency-Key` | | `getCharge` | Returns one charge by its `id` | | `listCharges` | Returns the charges of the environment, newest first, paginated by cursor | The route, the fields and the limits of each operation are in the [OpenAPI contract](/openapi.yaml), under these names. ## Creating a charge [#creating-a-charge] You send the amount, in cents, and in how many seconds the charge expires. The answer is the charge, with the state `pending` and its `br_code`. `br_code` is the PIX copy-and-paste code, and it is also the content of the QR code. Render it as a QR code for the payer to scan, or show it as text for the payer to paste into their banking app. The amount and the expiration never change after creation. ## States [#states] The state is the `status` field. | State | Meaning | |---|---| | `pending` | Waiting for payment | | `paid` | Paid | | `expired` | Expired without payment | | `disputed` | The payer disputed the payment at their bank, and the bank is holding the amount until it decides. See [Disputes](/docs/disputes) | | `refunded` | The amount went back to the payer, by a refund or by a dispute the bank accepted. Final: it never changes again | | From | To | When | |---|---|---| | `pending` | `paid` | The bank confirms the payment | | `pending` | `expired` | The expiration passes without payment | | `expired` | `paid` | The bank confirms a payment made at the last moment, after the charge had already expired on the platform | | `paid` | `refunded` | A refund of the charge reaches the payer. See [Refunds](/docs/refunds) | | `paid` | `disputed` | The bank holds the amount because the payer disputed the payment | | `disputed` | `paid` | The bank refuses the dispute | | `disputed` | `refunded` | The bank accepts the dispute and sends the amount back to the payer | Three rules follow from the tables: - **`expired` is not final.** An `expired` charge can still become `paid`. Handle a payment whenever it arrives. - **A `paid` charge becomes `refunded` or `disputed`, and only `disputed` comes back to `paid`.** The charge keeps its `paid_at` in the three states. While a refund is in progress the charge is still `paid`. - **Handle an unknown state without failing.** In the contract `status` is an open string, not an enum, for this reason. ## Listing charges [#listing-charges] `listCharges` returns the newest charges first. Each page brings `next_cursor`: pass it as `cursor` to read the next page. A `null` `next_cursor` means this is the last page. ## Idempotency [#idempotency] Creating a charge requires the `Idempotency-Key` header: a value that you choose, unique for each charge you intend to create. A UUID is fine. | You repeat the request with | Result | |---|---| | The same `Idempotency-Key` and the same body | The charge that was already created is returned. No new charge is created | | The same `Idempotency-Key` and a different body | `422` with the `idempotency_key_reused` code | | A different `Idempotency-Key` | A new charge | - The key is unique per environment. - Two requests are the same when they ask for the same amount and the same expiration. The order of the fields and the whitespace of the JSON do not matter. - The key never expires. Repeating a request with a key used long ago still returns that charge, as it is now: it may already be `paid` or `expired`. - Simultaneous requests with the same key create a single charge, and all of them receive it. - If a request fails with a network error or a timeout, repeat it with the same key. It is safe. ## Charges from an offer [#charges-from-an-offer] An [offer](/docs/offers) is something for sale at a fixed price, with a checkout page. Each purchase of an offer creates a charge in the environment of the offer. It is a charge like any other: it has the same states, it sends the same webhooks, and `getCharge` and `listCharges` return it. Two fields of the charge tell where it came from. Both are in the `Charge` schema of the contract, and both are `null` in a charge created by `createCharge`. - **`offer_id` is the offer that was bought.** The amount of the charge is the price the offer had at the purchase. - **`customer` is who bought**, with the name and the e-mail address typed at the purchase. The e-mail address was not verified. - **The customer is not necessarily the payer.** The PIX can leave the bank account of another person. A webhook carries only the id of the charge. When `charge.paid` arrives, read the charge with `getCharge` to know which offer was bought and by whom. ## Identifiers [#identifiers] The `id` of a charge follows the [TypeID](https://github.com/jetify-com/typeid) format: the prefix `chg`, an underscore, and 26 characters of base32 that encode a UUIDv7. For example, `chg_01h455vb4pex5vsknk084sn02q`. - The prefix tells the type. An identifier of another type is refused where a charge is expected. - The identifier of an offer has the same format, with the prefix `ofr`, and the one of a refund, with the prefix `rfd`. - The identifier reveals when the charge was created. Treat the part after the underscore as opaque. ## Charges of another environment [#charges-of-another-environment] Asking for a charge that does not belong to the environment of your key returns `404` with the `charge_not_found` code, exactly as if it did not exist. # Disputes (/docs/disputes) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. What happens when a payer disputes a PIX at their bank: the amount is held, and the bank decides. A dispute starts outside the platform: the payer tells their bank that a PIX was a fraud or a mistake, and the bank holds the amount while it decides. In PIX this is the Special Return Mechanism (MED). You do not ask for a dispute and cannot stop one: the platform learns of it from the bank, and tells you. ## What a dispute does [#what-a-dispute-does] - **The charge becomes `disputed`**, and the `charge.dispute.created` event is sent. - **The amount leaves your balance at once**, even if you already withdrew it. In that case the balance becomes negative, and the next sales cover it. - **The fee follows the rule of [refunds](/docs/refunds#the-amount).** By default the platform holds back the fee of the charge together with what the charge left in your balance. In an account set to leave the fee with the platform, the full amount comes out of your balance. - **A `disputed` charge cannot be refunded.** The answer is `409` with the `charge_disputed` code: the bank decides where the amount goes. ## How it ends [#how-it-ends] The bank decides, and the `charge.dispute.closed` event is sent either way. Read the charge to see the outcome. | Outcome | The charge becomes | What happens to the amount | |---|---|---| | The bank refuses the dispute | `paid` again | It goes back to your balance | | The bank accepts the dispute | `refunded`. Final | The bank sends it back to the payer. `charge.refunded` is sent as well | - A charge that is `paid` again can be refunded, and can be disputed again. - There is no `charge.paid` event when a dispute is refused: the payment happened once. - The platform does not send a defense to the bank in this version: the outcome is the one the bank gives. ## Events [#events] | Event | When | `data.id` | |---|---|---| | `charge.dispute.created` | The bank is holding the amount, and the charge became `disputed` | The charge | | `charge.dispute.closed` | The bank decided, and the charge became `paid` or `refunded` | The charge | | `charge.refunded` | The charge became `refunded`, together with `charge.dispute.closed`, when the bank accepted the dispute | The charge | A dispute is not an object of the API: it has no `id` and no route. The charge carries everything you need to act on. ## In test mode [#in-test-mode] Three operations, available only with a test key, play the part of the banks. See [Test mode](/docs/test-mode#simulating-a-dispute). # Errors (/docs/errors) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. The format of error responses, the error codes, and what to do with each one. Every error response has the media type `application/problem+json`, the format defined by [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457). ## Format [#format] | Member | Content | |---|---| | `code` | The stable identifier of the error. This is what your code reads | | `status` | The HTTP status of the response | | `title` | A short summary, the same for every error with the same `code`. For people | | `detail` | What is wrong with this request, when there is more to say than the title. For people | | `request_id` | The request id, the same as in the `X-Request-Id` header | | `errors` | Only on a validation error: each point of the request that the contract refuses | Each item of `errors` says where the problem is, with `pointer` (a JSON pointer into the body) or `parameter` (the name of a path parameter, a query parameter or a header), and what the contract expected there, in `detail`. Two rules: - **Decide by `code`, never by `title` or `detail`.** A published code does not change. The text may. - **The list of codes grows.** Handle an unknown code by its `status`. ## Codes [#codes] | `code` | Status | Meaning | What to do | |---|---|---|---| | `invalid_request` | `400` | The request does not follow the contract | Fix the request: `errors` says where. Sending the same request again does not help | | `unauthorized` | `401` | There is no valid API key | Check the key and its environment. See [Authentication](/docs/authentication) | | `insufficient_scope` | `403` | The API key is valid and does not have the scope the operation asks for | Use a key created with the scope. See [What a key can do](/docs/authentication#what-a-key-can-do) | | `origin_not_allowed` | `403` | A request to the MCP endpoint carried the `Origin` header, as a request made by a web page does | Call the MCP endpoint from a program, not from a page. See [MCP](/docs/mcp#connecting) | | `not_found` | `404` | The API has no operation with this method at this path | Check the method and the path against the contract | | `charge_not_found` | `404` | There is no charge with this `id` in the environment of the API key | Check the `id`, and that the key is of the environment where the charge was created | | `refund_not_found` | `404` | There is no refund with this `id` in the environment of the API key | Check the `id`, and that the key is of the environment where the refund was asked for | | `offer_not_found` | `404` | There is no offer with this `id` in the environment of the API key | Check the `id`, and that the key is of the environment where the offer was created | | `charge_not_payable` | `409` | In test mode, the simulated bank no longer pays this charge, because it expired | Create another charge. See [Test mode](/docs/test-mode) | | `charge_not_paid` | `409` | The charge to refund was never paid | Refund only a `paid` charge. See [Refunds](/docs/refunds) | | `charge_already_refunded` | `409` | The charge was already refunded, or has a refund in progress | Read the refund that exists instead of asking for another | | `charge_disputed` | `409` | The payer disputed the charge, and the bank is holding its amount | Wait for the `charge.dispute.closed` event. See [Disputes](/docs/disputes) | | `charge_not_disputable` | `409` | In test mode, the simulated bank does not dispute this charge: it is not `paid`, or its payment has nothing left to dispute | Simulate the dispute of a `paid` charge. See [Test mode](/docs/test-mode) | | `charge_not_disputed` | `409` | In test mode, the charge has no open dispute to decide | Simulate the dispute first, and wait for the charge to become `disputed`. See [Test mode](/docs/test-mode) | | `refund_window_closed` | `409` | The charge was paid more than 90 days ago | PIX no longer returns this payment: settle it with the payer another way | | `insufficient_balance` | `409` | The balance of the environment does not cover the refund | Nothing was refunded. Ask again when the balance covers the amount, with the same `Idempotency-Key` | | `payload_too_large` | `413` | The body is too large | Send a smaller body | | `unsupported_media_type` | `415` | The body is not declared as JSON | Send the body as `application/json`, and say so in the `Content-Type` header | | `offer_invalid` | `422` | The name of the offer is only blank space | Send a name the buyer can read. See [Offers](/docs/offers#creating-an-offer) | | `idempotency_key_reused` | `422` | The `Idempotency-Key` already served a different request: another charge, or the refund of another charge | Use a new key for a new charge or a new refund. See [Idempotency](/docs/charges#idempotency) | | `rate_limited` | `429` | Too many requests | Wait the number of seconds in the `Retry-After` header | | `internal_error` | `500` | The platform failed | Try again, with the same `Idempotency-Key` when creating a charge or asking for a refund | | `live_mode_unavailable` | `501` | Creating a charge with a live key, while the real bank is not connected yet | Use a test key | ## Internal errors [#internal-errors] An `internal_error` carries only the code and the request id, never internal details. If it persists, send the `request_id` to support: it is what locates the request in the platform logs. # Introduction (/docs) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. What the API does, the conventions it follows, and how to read these docs. Xase is a payments platform for people who sell online. The first version accepts PIX only: you create a charge, the payer pays the QR code, and the platform tells your server when the money arrives. When you need to give the money back, you refund the charge. To sell without building a payment page, you create an offer and share the address of its checkout. ## What the first version covers [#what-the-first-version-covers] | Resource | What it does | Page | |---|---|---| | Charges | Create, read and list PIX charges | [Charges](/docs/charges) | | Refunds | Send the amount of a paid charge back to the payer | [Refunds](/docs/refunds) | | Disputes | Follow a payment that the payer disputed at their bank | [Disputes](/docs/disputes) | | Offers | Put something on sale at a fixed price, with a checkout page that creates the charges | [Offers](/docs/offers) | | Balance | Read what the sales left: available, pending, held by a dispute and on its way out | [Balance](/docs/balance) | | Webhooks | Notify your server of every state change | [Webhooks](/docs/webhooks) | | Test mode | Run the whole integration without real money | [Test mode](/docs/test-mode) | The statement and the payouts are in the dashboard, under **Saldo**. They are not part of the API, and have no page here. ## The contract [#the-contract] The API is described by an OpenAPI 3.1 document, served at [`/openapi.yaml`](/openapi.yaml). It is the source of truth for routes, fields and limits. These pages explain behavior and point to it. - A request with a field, a query parameter or a route that is not in the contract is refused. - A response may gain fields over time. Ignore the ones you do not know. ## Conventions [#conventions] - **HTTP and JSON**, under the `/v1` prefix. No SDK is required. - **Money is an integer number of cents.** BRL 10.00 is `1000`. Never a floating-point number. - **Time is UTC**, in the RFC 3339 format. - **Identifiers carry a type prefix**, such as `chg_…` for a charge. See [Identifiers](/docs/charges#identifiers). - **Every response carries the request id** in the `X-Request-Id` header. Quote it when asking for support. - **Errors use `application/problem+json`** (RFC 9457), and your code reads the `code` member. See [Errors](/docs/errors). - **Creating a charge and asking for a refund are idempotent**: both require the `Idempotency-Key` header. See [Idempotency](/docs/charges#idempotency). ## For AI agents [#for-ai-agents] Everything in the HTML pages is also served as plain text: | File | Content | |---|---| | [`/llms.txt`](/llms.txt) | Index with a link to the Markdown of every page | | [`/llms-full.txt`](/llms-full.txt) | Every page in a single file | | `.md` | The Markdown of one page, such as [`/docs/charges.md`](/docs/charges.md) | | [`/openapi.yaml`](/openapi.yaml) | The OpenAPI contract | A request to any page with the header `Accept: text/markdown` gets the Markdown instead of the HTML. An agent can also call the API itself, through the [MCP server](/docs/mcp): every operation of the contract is a tool. # MCP (/docs/mcp) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. Connect an AI agent to the API through the Model Context Protocol, with every operation as a tool. The API has a [Model Context Protocol](https://modelcontextprotocol.io) server, at `/mcp` on the same host as `/v1`. It is the public API by another transport: every operation of the [OpenAPI contract](/openapi.yaml) is a tool, and calling a tool is making the request of that operation. Validation, scopes, idempotency, errors and rate limits are the same. ## Connecting [#connecting] - **Endpoint:** `POST /mcp`. - **Transport:** Streamable HTTP, without sessions. Each `POST` stands on its own. - **Protocol revision:** `2026-07-28`, and the earlier revisions for clients that have not moved yet. - **Credential:** the API key, in the `Authorization` header, as `Bearer sk_test_…`. The key is the same one that `/v1` takes, and it decides the environment: a test key connects the agent to test mode, a live key to live. See [Authentication](/docs/authentication). There is no OAuth sign-in: a client connects only if it can send a fixed header. | Client | Where the header goes | |---|---| | [Claude Code](https://code.claude.com/docs/en/mcp) | `claude mcp add --transport http xase https://API_HOST/mcp --header "Authorization: Bearer sk_test_…"` | | [Claude](https://support.claude.com/en/articles/11175166-getting-started-with-custom-connectors-using-remote-mcp) | In **Customize > Connectors**, add a custom connector with the URL of `/mcp`, choose **No sign in**, and under **Request headers** add `Authorization` with the value `Bearer sk_test_…` | | [Cursor](https://cursor.com/docs/context/mcp) | In `mcp.json`, a server with `"url"` and `"headers": {"Authorization": "Bearer ${env:XASE_API_KEY}"}` | | [VS Code](https://code.visualstudio.com/docs/agents/reference/mcp-configuration) | In `.mcp.json`, a server with `"type": "http"`, `"url"` and `"headers": {"Authorization": "Bearer ${XASE_API_KEY}"}` | `API_HOST` stands for the host of the API. A client that only connects through OAuth, such as ChatGPT, cannot connect. - Without a valid key the answer is `401`, the same as in `/v1`. Some clients react to a `401` by starting an OAuth sign-in, which leads nowhere here: set the header. - A request that carries the `Origin` header is refused with `403` and the code `origin_not_allowed`. The endpoint is for programs, and a browser sends that header when a web page makes the request. - `GET` and `DELETE` answer `405`: there is no stream and no session to open or close. - The server has tools only: no resources, no prompts, and it never asks the client for anything. ## Tools [#tools] Each tool has the name of its operation in the contract, such as `createCharge`, and the description the contract gives it. The pages of each resource say what the operations do: [Charges](/docs/charges), [Refunds](/docs/refunds), [Disputes](/docs/disputes), [Offers](/docs/offers), [Balance](/docs/balance) and [Test mode](/docs/test-mode). The arguments of a tool are the fields of the request body of the operation, plus one argument for each of its parameters, under the name the contract gives it: | In the contract | In the tool | Example | |---|---|---| | A field of the request body | An argument with the same name | `amount_cents` | | A path parameter | An argument with the same name | `id` | | A query parameter | An argument with the same name | `limit` | | A header | An argument with the same name | `Idempotency-Key` | So `createCharge` takes `amount_cents`, `expires_in` and `Idempotency-Key`, and `getCharge` takes `id`. An argument the contract does not have is refused, like a field that is not in the contract is refused in `/v1`. The result of a tool is the JSON the operation answers, as text and as structured content. An operation that answers without a body, like `simulatePayment`, returns the description of that answer. ## The tools a key sees [#the-tools-a-key-sees] The list of tools is the list of what the key can do: - Every operation asks the key for a scope, and a tool only appears for a key that has the scope of its operation. See [What a key can do](/docs/authentication#what-a-key-can-do). - A key with the `read` scopes alone sees the seven tools that read, `getCharge`, `listCharges`, `getRefund`, `listRefunds`, `getOffer`, `listOffers` and `getBalance`, and none that writes. - Writing does not include reading: a key with `charges:write` alone sees `createCharge` and not `getCharge`. - A key created before an operation existed does not see its tool. Offers and the balance came after the first keys: an agent sees `createOffer` or `getBalance` only with a key created with their scopes. - The tools of [test mode](/docs/test-mode) only appear for a test key, and ask it for the same scope as their operations, `charges:write`. Calling a tool that is not in the list of the key answers like calling a tool that does not exist. To give an agent fewer tools, give it a key with fewer scopes. ## Errors [#errors] When the operation refuses the call, the result is marked as an error (`isError`) and its text is the same `problem` that `/v1` answers. Read `code`, as in [Errors](/docs/errors): `invalid_request` lists each argument that the contract refuses, by the name of the argument. A tool call spends the rate limit of the key, from the same bucket as the requests to `/v1`. Over the limit the result is the `rate_limited` error, and a second text block says in how many seconds to try again, as `Retry-After: 4`. When you retry `createCharge` or `createRefund`, send the same `Idempotency-Key`: the call returns what the first one created. `createOffer` has no `Idempotency-Key`, and every call creates another offer: after a call that did not answer, call `listOffers` before trying again. ## What to give an agent [#what-to-give-an-agent] - **Start with a test key.** The whole path runs in test mode: `createCharge` and `simulatePayment` with `charges:write`, `getCharge` with `charges:read`, `createRefund` with `refunds:write`, `createOffer` and `archiveOffer` with `offers:write`, and `getBalance` with `balance:read`. - **Give the agent the key with the fewest scopes that does the job.** An agent that only answers questions needs the `read` scopes and nothing else. A key without `refunds:write` cannot refund, whatever the agent is told. - **Text typed by a buyer reaches the model.** The `customer` of a charge carries the name and the e-mail address the buyer typed at the checkout, and that text can be written as an instruction. An agent that holds a key with `refunds:write` can be talked into a refund. The damage has a ceiling: a refund only sends back to the payer what the payer paid, once. - **Keep the confirmation of your client on.** The tools that only read are marked as read-only, and every other tool is marked as destructive, which is what a client uses to ask before calling it. The mark is a hint to the client, not a control of the platform. # Offers (/docs/offers) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. Something on sale at a fixed price, with a checkout page: how to create it, share its address and take it off sale. An offer is something on sale at a fixed price, with a checkout page of its own. You create the offer, give the address of its checkout to buyers, and each purchase made there becomes a charge. ## Operations [#operations] | Operation in the contract | What it does | |---|---| | `createOffer` | Puts an offer on sale and returns it, with its `checkout_url`. Requires the `offers:write` scope | | `getOffer` | Returns one offer by its `id`, on sale or archived. Requires the `offers:read` scope | | `listOffers` | Returns the offers of the environment, newest first, paginated by cursor. Requires the `offers:read` scope | | `archiveOffer` | Takes an offer off sale, for good, and returns it. Requires the `offers:write` scope | The route, the fields and the limits of each operation are in the [OpenAPI contract](/openapi.yaml), under these names. The offers of the API are the ones of the dashboard, in **Ofertas**: an offer created in one appears in the other. ## What a key needs [#what-a-key-needs] - **`offers:write` to create and to archive, `offers:read` to read and to list.** Writing does not include reading: a key with `offers:write` alone creates an offer and cannot read it back. See [What a key can do](/docs/authentication#what-a-key-can-do). - **A key created before offers were in the API has neither scope.** A scope is never added to a key that exists: create another key in the dashboard. - Without the scope the answer is `403` with the `insufficient_scope` code. ## Creating an offer [#creating-an-offer] You send the name, as the buyer will read it on the checkout page, and the price, in cents. The answer is the offer, on sale at once. - **The name and the price never change.** To change one, archive the offer and create another. - **A name that is only blank space is refused**, with `422` and the `offer_invalid` code. - **There is no `Idempotency-Key`: every call creates another offer.** If a request fails with a network error or a timeout, list the offers before trying again. An offer created twice by mistake can be archived. - **With a live key the offer is created, and it cannot be bought yet.** The real bank is not connected. Use a test key. ## The checkout address [#the-checkout-address] `checkout_url` is the address of the checkout page of the offer. Whoever opens it can buy, without an account: the buyer types a name and an e-mail address and receives a PIX code to pay. - **Use the address as the API returns it.** Do not build it from the `id`. - **An address you already gave out keeps working.** It is safe to put in an e-mail, an ad or a page: if the checkout ever moves, the old address leads to the new one. - **It stops selling when the offer is archived.** ## What a purchase creates [#what-a-purchase-creates] Each purchase creates a charge in the environment of the offer, for the price of the offer. The charge expires 24 hours after the purchase. - It is a charge like any other: it has the same states, it sends the same webhooks, and `getCharge` and `listCharges` return it to a key with `charges:read`. - Its `offer_id` is the offer, and its `customer` is who bought. See [Charges from an offer](/docs/charges#charges-from-an-offer). - There is no filter by offer. To know what an offer sold, read the charges page by page and keep the ones with its `offer_id`. - In test mode, pay the charge of a purchase with `simulatePayment`, like any other charge. See [Test mode](/docs/test-mode). An offer sends no webhook of its own. What happens to a purchase is told by the events of its charge. See [Webhooks](/docs/webhooks). ## Archiving an offer [#archiving-an-offer] `archiveOffer` takes the offer off sale, and there is no way back. The answer is the offer, with `archived_at`. - Archiving an archived offer changes nothing and returns it as it is. It is safe to repeat. - The charges the offer already created stay as they are, and a purchase that was already made can still be paid. - An archived offer is still returned by `getOffer` and `listOffers`. `archived_at` is `null` while the offer is on sale. ## Listing offers [#listing-offers] `listOffers` returns the newest offers first, on sale and archived. Each page brings `next_cursor`: pass it as `cursor` to read the next page. A `null` `next_cursor` means this is the last page. ## Identifiers [#identifiers] The `id` of an offer has the same format as the one of a charge, with the prefix `ofr`. For example, `ofr_01h455vb4pex5vsknk084sn02q`. See [Identifiers](/docs/charges#identifiers). ## Offers of another environment [#offers-of-another-environment] Asking for an offer that does not belong to the environment of your key, to read it or to archive it, returns `404` with the `offer_not_found` code, exactly as if it did not exist. # Refunds (/docs/refunds) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. Sending the amount of a paid charge back to the payer: what it takes, how it ends, and how to retry safely. A refund sends the amount of a paid charge back to the payer, by PIX. You ask for the refund, what it takes leaves your balance at once, and the bank returns the amount to the payer shortly after. ## Operations [#operations] | Operation in the contract | What it does | |---|---| | `createRefund` | Asks for the refund of a charge. Requires `Idempotency-Key` and the `refunds:write` scope | | `getRefund` | Returns one refund by its `id` | | `listRefunds` | Returns the refunds of the environment, newest first, paginated by cursor | The route, the fields and the limits of each operation are in the [OpenAPI contract](/openapi.yaml), under these names. ## What a refund takes [#what-a-refund-takes] - **A key with the `refunds:write` scope.** A key without it gets `403` with the `insufficient_scope` code. See [What a key can do](/docs/authentication#what-a-key-can-do). Reading and listing refunds ask for another scope, `refunds:read`. - **A `paid` charge.** A charge that was never paid answers `409` with the `charge_not_paid` code, and one that is `disputed`, `409` with the `charge_disputed` code: see [Disputes](/docs/disputes). - **One refund per charge.** A charge that was refunded, or has a refund in progress, answers `409` with the `charge_already_refunded` code. - **At most 90 days since the payment.** That is the window in which PIX accepts a return. After it the answer is `409` with the `refund_window_closed` code. - **Balance to cover it.** What the refund takes comes out of the balance of the environment: see [The amount](/docs/refunds#the-amount). Without enough balance the answer is `409` with the `insufficient_balance` code, and nothing is refunded. A refusal moves nothing: no refund is created and the balance stays as it was. ## The amount [#the-amount] - **A refund is always for the full amount of the charge.** There is no partial refund, and the payer gets the full amount back. - **By default the fee of the charge is returned with the refund.** The refund takes from your balance only what the charge left there, and the platform gives back the fee. A charge covers its own refund. - **The rule is a setting of your account.** An account can be set to leave the fee with the platform. Then the full amount comes out of your balance, and the balance left by a charge does not cover its own refund: the difference is the fee. - **A refund follows the rule in force when it was asked for.** Changing the setting does not change a refund that is `pending`. ## States [#states] The state is the `status` field. | State | Meaning | |---|---| | `pending` | What the refund takes left your balance, and the bank has not confirmed the return yet | | `succeeded` | The amount reached the payer, and the charge is `refunded`. Final | | `failed` | The bank did not make the return. What the refund took is back in your balance. Final | - A refund is created `pending`. The answer of `createRefund` never says how it ended: follow the [webhooks](/docs/webhooks), or read the refund. - After a `failed` refund the charge is still `paid`, and it can be refunded again, with a new `Idempotency-Key`. - Handle an unknown state without failing. In the contract `status` is an open string, not an enum, for this reason. ## Events [#events] | Event | When | `data.id` | |---|---|---| | `refund.created` | The refund was asked for, and what it takes left your balance | The refund | | `refund.succeeded` | The amount reached the payer | The refund | | `refund.failed` | The bank did not make the return, and what the refund took is back in your balance | The refund | | `charge.refunded` | The charge became `refunded`, together with `refund.succeeded` | The charge | To know which charge a refund event is about, read the refund with `getRefund`: `charge_id` says it. ## Idempotency [#idempotency] Asking for a refund requires the `Idempotency-Key` header: a value that you choose, unique for each refund you intend to ask for. A UUID is fine. | You repeat the request with | Result | |---|---| | The same `Idempotency-Key` and the same charge | The refund that already exists is returned, as it is now. No new refund is asked for | | The same `Idempotency-Key` and another charge | `422` with the `idempotency_key_reused` code | | A different `Idempotency-Key` and the same charge | `409` with the `charge_already_refunded` code, unless the earlier refund `failed` | - The key is unique per environment, among refunds. It does not collide with the key of a charge. - The key never expires. - Simultaneous requests for the same charge ask for a single refund. The ones with the same key receive it, and the others get `charge_already_refunded`. - If a request fails with a network error or a timeout, repeat it with the same key. It is safe: the money never goes back twice. ## Identifiers [#identifiers] The `id` of a refund has the same format as the one of a charge, with the prefix `rfd`. For example, `rfd_01h455vb4pex5vsknk084sn02q`. See [Identifiers](/docs/charges#identifiers). ## Refunds of another environment [#refunds-of-another-environment] Asking for a refund that does not belong to the environment of your key returns `404` with the `refund_not_found` code, exactly as if it did not exist. Asking to refund a charge of another environment returns `404` with the `charge_not_found` code. # Test mode (/docs/test-mode) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. Run the whole integration, from the QR code to the webhook, without moving money. Test mode is a complete, isolated environment: the same API and the same webhooks as live, with a simulated bank in place of the real one. It exists from the first version of the API. ## How to use it [#how-to-use-it] Use a key with the `sk_test_` prefix. There is no separate URL and no parameter: the key decides the environment. The operations that exist only in test mode ask the key for the `charges:write` scope. See [Authentication](/docs/authentication). ## What is the same as live [#what-is-the-same-as-live] - Routes, fields, validation and errors. - The life of a charge: it starts as `pending` and becomes `paid` or `expired`, and a `paid` charge can be refunded or disputed. - Refunds: the same rules, with the simulated bank returning the amount at once. See [Refunds](/docs/refunds). - Webhooks: the same events, the same signature, the same retries. ## What exists only in test mode [#what-exists-only-in-test-mode] **Simulating a payment.** There is no real payer in test mode, so one operation, available only with a test key, tells the simulated bank to pay a charge: `simulatePayment` in the [OpenAPI contract](/openapi.yaml). It answers `202`, and from there everything follows the real path: shortly after, the charge becomes `paid`, the event is recorded, and the signed webhook reaches your destination. - Read the charge again, or wait for the webhook, to see it `paid`. The `202` only says that the simulated bank registered the payment. - Simulating again on a charge that is already paid changes nothing. - A charge that already expired cannot be paid: the answer is `409` with the `charge_not_payable` code. - With a live key this route does not exist: the answer is `404` with the `not_found` code. ## Simulating a dispute [#simulating-a-dispute] No payer disputes a PIX in test mode either, so three operations, available only with a test key, play the part of the banks. Each answers `202`, and from there everything follows the real path: shortly after, the charge changes, the event is recorded, and the signed webhook reaches your destination. See [Disputes](/docs/disputes). | Operation in the contract | What the simulated bank does | The charge becomes | |---|---|---| | `simulateDispute` | Holds the amount of a `paid` charge, as if the payer had disputed it | `disputed` | | `simulateDisputeWon` | Refuses the open dispute | `paid` again | | `simulateDisputeLost` | Accepts the open dispute and sends the amount back to the payer | `refunded` | - Read the charge again, or wait for the webhook, before the next step: the outcome can only be simulated once the charge is `disputed`. - A charge that is not `paid`, or whose payment has nothing left to dispute, answers `409` with the `charge_not_disputable` code. - Deciding a charge that has no open dispute answers `409` with the `charge_not_disputed` code. - With a live key these routes do not exist: the answer is `404` with the `not_found` code. ## The path of an integration [#the-path-of-an-integration] 1. Create a charge with a test key. 2. Simulate its payment. 3. Read the charge and check that it is `paid`. 4. Receive the webhook on your server and verify its signature. All four steps are plain HTTP. ## Isolation [#isolation] Test data and live data never mix. A charge created with a test key cannot be read with a live key, and the reverse is also true: the request gets `404`. # Webhooks (/docs/webhooks) > Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml. How the platform tells your server about every state change, and how to verify the message. Every state change of a charge or of a refund, starting with its creation, records an **event**, and every event is delivered by HTTP `POST` to each destination registered in the environment. This is how your server learns that a PIX was paid, or that a refund reached the payer, without polling the API. ## Events [#events] - Every event has an identifier that starts with `evt_`. - The event is recorded in the same database transaction that changes the state. There is no state change without an event, and no event without the change. - The event types of a charge are `charge.created`, `charge.paid`, `charge.expired`, `charge.refunded`, `charge.dispute.created` and `charge.dispute.closed`: see [Disputes](/docs/disputes#events) for the last two. The ones of a refund are `refund.created`, `refund.succeeded` and `refund.failed`: see [Refunds](/docs/refunds#events). Answer `2xx` to an unknown type and ignore it: the list grows. - Each type is an entry in the `webhooks` section of the [OpenAPI contract](/openapi.yaml), with the body and the headers of the request. ## The body [#the-body] The body is small on purpose. It says what happened, when, and to which charge or refund: ```json { "type": "charge.paid", "timestamp": "2026-11-26T15:04:05.123456Z", "data": { "id": "chg_01h455vb4pex5vsknk084sn02q" } } ``` | Member | Content | |---|---| | `type` | The event type, the same as the name of the webhook in the contract | | `timestamp` | When the event happened, which is not when this attempt was sent | | `data.id` | The id of the charge, in a `charge.` event, or of the refund, in a `refund.` event | The event carries no other data of the charge or of the refund. Read it with `getCharge` or `getRefund` to see its current state: by the time a delivery arrives, it may already have changed again. The body may gain members, so ignore the ones you do not know. ## Destinations [#destinations] A destination is a URL of yours that receives the events of one environment. Each destination has its own secret. A destination is registered in the dashboard, in **Webhooks**, under the mode it is for. The dashboard shows its secret once, when the destination is registered. Registering and removing a destination ask for your passkey again when you signed in more than 5 minutes ago. | Rule | Consequence | |---|---| | The destination must be an `https://` address | Any other scheme is refused when the destination is registered | | An environment holds at most 16 destinations | Registering another is refused until one is removed | | The destination must be a public address | A delivery to an address in a private network fails, even when a public name points to it | | The destination must answer directly | Redirects are not followed | ## Verifying the signature [#verifying-the-signature] Deliveries follow the [Standard Webhooks](https://github.com/standard-webhooks/standard-webhooks) specification. Every request carries three headers: | Header | Content | |---|---| | `webhook-id` | The id of the event, which starts with `evt_`. It stays the same on every retry | | `webhook-timestamp` | When this attempt was sent, in seconds since the Unix epoch | | `webhook-signature` | The signature, as `v1,` | The signature is the HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}`, encoded in base64. The secret starts with `whsec_`, and the HMAC key is the rest of the secret, decoded from base64. To verify a delivery: 1. Use the raw body, byte for byte as received. Parsing and serializing the JSON again changes the bytes and breaks the signature. 2. Refuse a `webhook-timestamp` too far from the current time. This blocks replays. 3. Compute the signature and compare it with a constant-time comparison. Prefer a Standard Webhooks library over writing this by hand. The project publishes reference libraries for Python, JavaScript, Java, Go, Ruby, PHP, C#, Rust and Elixir. ## Retries and duplicates [#retries-and-duplicates] - A delivery succeeds when your server answers with a `2xx` status. Any other answer is a failure, and so is a redirect, or no answer within 15 seconds. - A failed delivery is tried again after 5 s, 5 min, 30 min, 2 h, 5 h, 10 h, 14 h, 20 h and 24 h. Each wait can be up to a tenth longer. That is ten attempts over a little more than three days. - After the last attempt the event is dropped for that destination. The destination stays registered and keeps receiving the next events. - A destination removed while a delivery was waiting does not receive it. - The same event can therefore arrive more than once. Store the `webhook-id` and ignore a repeated one. Otherwise an order may be fulfilled twice. - Events can arrive out of order. The `timestamp` of the body says when each one happened.