TgPay Crypto Exchange API
Exchange of the app balance between assets.
Exchange of the app balance between assets.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/tgpaycrypto-com:tgpaycrypto-com-exchange-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
openapi: 3.2.0
info:
title: TgPay Crypto Merchant Exchange API
version: '2026-11-16'
summary: Merchant payments API of the TgPay Crypto wallet (@tgpaycryptobot).
description: 'The Merchant API of TgPay Crypto (@tgpaycryptobot): create
invoices, refund them, send payouts and checks, withdraw the app
balance on-chain, exchange it between assets, issue withdrawal links,
manage recurring subscriptions, and receive signed webhooks. Human-readable documentation: https://docs.tgpaycrypto.com/crypto-pay-api-reference/
## Conventions
- **Authentication** — send your token in `TgPayCrypto-API-Token`. `TgCryptoPay-API-Token` and `Crypto-Pay-API-Token` are accepted aliases,
in that order. The first non-empty header wins. Full-access primary
tokens have every scope except `withdraw`; restricted tokens need the
operation''s scope, and only a restricted token can hold `withdraw`. - **Envelope** — application success is HTTP 200 with `{ok: true, result}`;
application errors are `{ok: false, error: {code, name}}`, with `code`
equal to the HTTP status. Branch on `error.name`. Transport/framework
rejections, such as malformed typed query parameters, may lack this envelope. - **Amounts** — requests use decimal strings in whole-coin or fiat units,
never JSON numbers. Crypto input is rounded to the asset''s minor unit,
with midpoint rounding away from zero; the result must be positive. Fiat input must represent a positive exact number of cents, at most
10^13 whole fiat units. Responses use fixed-point strings; balance and
fee amounts can be zero. `*_minor` values are integer strings. `getCurrencies` supplies asset decimals. Send exact asset precision. - **POST parameters** — JSON object, form-urlencoded body, or URL query
parameters; body values override query values, including null. Repeated
form/query keys use the last value. Multipart is rejected. Money-moving
methods have no GET aliases. Nested `items` and `recipients` must be
JSON arrays in a JSON body; JSON-encoded strings do not work for them. Required fields must be present after merging query and body. Optional null values generally behave as omitted; per-field rules apply. Integers accept integer strings; booleans also accept 1/0 and the strings
true/false, 1/0, yes/no, on/off (case-insensitive, surrounding whitespace ignored). Text limits are measured in UTF-16 code units by the server. - **Idempotency** — `spend_id` is required for transfers, batch items,
withdraw and exchange, optional for checks and refunds. Empty/null
optional keys disable replay. Keys are scoped per app and operation;
transfer, transferBatch and withdraw share a namespace, exchange has its
own. After validation and access gates, the same parsed request
replays its stored success. Different input returns `409 idempotency_conflict`;
an unfinished claim returns `409 idempotency_in_progress`. Amount strings
and recipient spelling are not normalized for the request hash: keep them
identical on retries. Replays are snapshots, not refreshed objects; use
list methods to obtain current status. createInvoice and plan creation
have no spend_id idempotency; createInvoice''s retry key is
`client_invoice_id`. - **Per-operation webhook and payload** — createInvoice, createCheck,
transfer, each transferBatch item and withdraw accept `webhook_url`
(a public HTTPS URL, up to 256 characters): every update of that
operation goes there instead of the app''s URL, regardless of the app''s
event selection. It is not returned in objects. createCheck, transfer,
transferBatch items and withdraw also accept `payload` (up to 4096
characters), echoed in the object and its webhooks. - **Pagination** — invoices, checks, transfers, withdrawals, exchanges and
withdrawal links default to offset 0, count 100; the server clamps
offset to at least 0 and count to 1..1000. Subscriptions clamp count to 1..500. These lists return `{items: [...]}`,
newest first. getSubscriptionPlans returns all plans without pagination. - **Timestamps** — ISO-8601 strings; nullable timestamps are explicitly null.'
servers:
- url: https://app.tgpaycrypto.com/pay/api
description: Production
- url: https://testnet.tgpaycrypto.com/pay/api
description: Testnet — coins with no value, its own bot @tgpaycrypto_testnet_bot and its own apps and tokens
security:
- apiToken: []
- apiTokenLegacy: []
- apiTokenCompat: []
tags:
- name: Exchange
description: Exchange of the app balance between assets.
paths:
/getExchangePairs:
get:
tags:
- Exchange
operationId: getExchangePairs
summary: What the app can exchange
description: 'Scope: `read`.
Any two different assets of `assets` form a pair. USD values are
strings with two decimal places. Specific errors:
`403 exchange_unavailable` (exchange through the API is switched off
for the service), `409 exchange_disabled` (exchange temporarily
unavailable).'
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- ok
- result
properties:
ok:
const: true
result:
$ref: '#/components/schemas/ExchangePairs'
default:
$ref: '#/components/responses/Error'
/getExchangeEstimate:
get:
tags:
- Exchange
operationId: getExchangeEstimate
summary: Estimate an exchange
description: 'Scope: `read`. Rate limit: 60/min per app.
Pass exactly one of `amount` (how much `asset_from` to give) or
`amount_to` (how much `asset_to` to receive). Moves no funds and
reserves no rate. Runs the same asset, bounds, daily-limit and capacity
checks as exchange (not the balance or owner restrictions) and returns
the same errors, plus `400 invalid_request` (both or neither amount)
and `403 exchange_unavailable`. Pass the estimate''s `amount_to` to
exchange as `min_amount_to`, or its `amount_from` as `max_amount_from`.'
parameters:
- name: asset_from
in: query
required: true
schema:
type: string
- name: asset_to
in: query
required: true
schema:
type: string
- name: amount
in: query
schema:
$ref: '#/components/schemas/AmountInput'
description: How much asset_from to give. Exactly one of amount / amount_to.
- name: amount_to
in: query
schema:
$ref: '#/components/schemas/AmountInput'
description: How much asset_to to receive. Exactly one of amount / amount_to.
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- ok
- result
properties:
ok:
const: true
result:
$ref: '#/components/schemas/ExchangeEstimate'
default:
$ref: '#/components/responses/Error'
/exchange:
post:
tags:
- Exchange
operationId: exchange
summary: Exchange the app balance between assets
description: 'Scope: `exchange`. Rate limit: 30/min per app. Shared outgoing-funds
restrictions apply (`403 verification_required`,
`503 merchant_payouts_paused`); the payout mode and daily payout
ceiling do not — nothing leaves the app.
Exchanges at the rate in effect at the call; there is no stored quote.
Pass exactly one of `amount` (give exactly this much `asset_from`;
guard with `min_amount_to`) or `amount_to` (receive exactly this much
`asset_to`; the spend is rounded up; guard with `max_amount_from`).
`spend_id` is required and has its own namespace. Each completed
exchange also sends the opt-in `exchange_completed` webhook.
Specific errors: `400 invalid_request` (missing parameter, both or
neither of `amount` / `amount_to`, a guard that doesn''t match the
mode), `400 unknown_asset`, `400 invalid_amount`, `400 same_asset`,
`400 amount_too_small`, `400 exchange_min` / `exchange_max`,
`409 exchange_daily_limit`, `409 exchange_capacity`,
`409 exchange_disabled` / `exchange_asset_disabled`, `409 rate_moved`
(a guard was not met; nothing moved), `409 insufficient_funds`,
`503 rates_unavailable`, `403 exchange_unavailable` (exchange through
the API is switched off for the service),
`409 idempotency_conflict` / `idempotency_in_progress`.'
requestBody:
required: false
content:
application/json:
schema:
$ref: '#/components/schemas/ExchangeRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/ExchangeRequest'
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- ok
- result
properties:
ok:
const: true
result:
$ref: '#/components/schemas/Exchange'
default:
$ref: '#/components/responses/Error'
parameters:
- name: asset_from
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/asset_from'
- name: asset_to
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/asset_to'
- name: amount
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/amount'
- name: amount_to
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/amount_to'
- name: spend_id
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/spend_id'
- name: min_amount_to
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/min_amount_to'
- name: max_amount_from
in: query
required: false
description: Alternative to this field in the body; body wins. Required-field rules apply after merging.
schema:
$ref: '#/components/schemas/ExchangeRequest/properties/max_amount_from'
/getExchanges:
get:
tags:
- Exchange
operationId: getExchanges
summary: List exchanges
description: 'Scope: `read`. Newest first. Only the app''s own exchange calls;
invoice `swap_to` conversions are recorded on the invoice. Unparsable
ids match nothing. Specific errors: `403 exchange_unavailable`.'
parameters:
- name: exchange_ids
in: query
schema:
type: string
description: Comma-separated exchange_id UUIDs.
- name: spend_id
in: query
schema:
type: string
description: Exact match.
- name: offset
in: query
schema:
type: integer
default: 0
- name: count
in: query
schema:
type: integer
default: 100
minimum: 1
maximum: 1000
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- ok
- result
properties:
ok:
const: true
result:
type: object
required:
- items
properties:
items:
type: array
items:
$ref: '#/components/schemas/Exchange'
default:
$ref: '#/components/responses/Error'
components:
schemas:
AmountInput:
type: string
minLength: 1
maxLength: 40
description: Positive amount as a decimal string (not a JSON number). Surrounding whitespace and exponent notation are accepted. Crypto rounds to asset precision, midpoint away from zero, and must remain positive; fiat requires exact positive cents. Values must fit the server decimal parser and scaling arithmetic.
pattern: ^\s*\+?(?=[0-9.]*[1-9])(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?\s*$
Amount:
type: string
description: Non-negative fixed-point decimal string in whole-coin (or fiat) units, including zero balances and fees. Never a JSON number.
examples:
- '10.5'
pattern: ^[0-9]+(?:\.[0-9]+)?$
ExchangeRequest:
type: object
required:
- asset_from
- asset_to
- spend_id
properties:
asset_from:
type: string
maxLength: 16
asset_to:
type: string
maxLength: 16
amount:
anyOf:
- $ref: '#/components/schemas/AmountInput'
description: Give exactly this much asset_from. Exactly one of amount / amount_to.
- type: 'null'
amount_to:
anyOf:
- $ref: '#/components/schemas/AmountInput'
description: Receive exactly this much asset_to; the spend is rounded up. Exactly one of amount / amount_to.
- type: 'null'
spend_id:
type: string
minLength: 1
maxLength: 64
description: Required idempotency key; exchanges have their own namespace.
min_amount_to:
anyOf:
- $ref: '#/components/schemas/AmountInput'
description: With amount only — the least asset_to accepted, else 409 rate_moved.
- type: 'null'
max_amount_from:
anyOf:
- $ref: '#/components/schemas/AmountInput'
description: With amount_to only — the most asset_from to give, else 409 rate_moved.
- type: 'null'
oneOf:
- required:
- amount
properties:
amount:
$ref: '#/components/schemas/AmountInput'
amount_to:
type: 'null'
max_amount_from:
type: 'null'
- required:
- amount_to
properties:
amount_to:
$ref: '#/components/schemas/AmountInput'
amount:
type: 'null'
min_amount_to:
type: 'null'
ExchangePairs:
type: object
properties:
assets:
type: array
items:
type: string
description: Any two different assets of the list form a pair.
min_usd:
$ref: '#/components/schemas/UsdAmount'
max_usd:
$ref: '#/components/schemas/UsdAmount'
daily_max_usd:
allOf:
- $ref: '#/components/schemas/UsdAmount'
description: The app's rolling 24-hour limit; "0.00" = no limit.
daily_used_usd:
$ref: '#/components/schemas/UsdAmount'
required:
- assets
- min_usd
- max_usd
- daily_max_usd
- daily_used_usd
Exchange:
type: object
description: The exchange object — exchange, getExchanges and the exchange_completed webhook.
properties:
exchange_id:
type: string
format: uuid
spend_id:
type: string
asset_from:
type: string
asset_to:
type: string
amount_from:
$ref: '#/components/schemas/Amount'
amount_to:
$ref: '#/components/schemas/Amount'
rate:
type: string
description: asset_to per one unit of asset_from, margin included.
status:
type: string
const: completed
description: Only executed exchanges are recorded.
created_at:
type: string
format: date-time
required:
- exchange_id
- spend_id
- asset_from
- asset_to
- amount_from
- amount_to
- rate
- status
- created_at
UsdAmount:
type: string
pattern: ^[0-9]+\.[0-9]{2}$
examples:
- '100.00'
description: USD as a decimal string with two decimal places.
ErrorEnvelope:
type: object
required:
- ok
- error
properties:
ok:
const: false
error:
type: object
required:
- code
- name
properties:
code:
type: integer
description: Duplicates the HTTP status (400/401/403/404/409/429/503/500).
name:
type: string
description: Machine-readable error name to branch on, e.g. "insufficient_funds".
ExchangeEstimate:
type: object
properties:
asset_from:
type: string
asset_to:
type: string
amount_from:
$ref: '#/components/schemas/Amount'
amount_to:
$ref: '#/components/schemas/Amount'
rate:
type: string
description: asset_to per one unit of asset_from, margin included.
required:
- asset_from
- asset_to
- amount_from
- amount_to
- rate
responses:
Error:
description: 'Error — `{"ok": false, "error": {"code": <HTTP status>, "name":
"<machine_name>"}}` with the same HTTP status on the wire. See the
operation description for its specific error names and the API
description for the common ones.
'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
securitySchemes:
apiToken:
type: apiKey
in: header
name: TgPayCrypto-API-Token
description: The canonical token header. The token is shown once, at app creation or rotation.
apiTokenLegacy:
type: apiKey
in: header
name: TgCryptoPay-API-Token
description: The canonical header's name before 2026-09-07 — still accepted, so integrations built earlier keep working unchanged.
apiTokenCompat:
type: apiKey
in: header
name: Crypto-Pay-API-Token
description: Accepted token header alias. The first non-empty canonical/legacy/compatibility header wins, in that order.
externalDocs:
description: Merchant API reference (developer docs)
url: https://docs.tgpaycrypto.com/crypto-pay-api-reference/