API reference
API overview
A REST API with JSON bodies. The pages of this reference are generated from its OpenAPI specification, so they always match the service.
Base URLs
Section titled “Base URLs”| Environment | Base URL | Keys |
|---|---|---|
| Testnet: Sepolia, BSC testnet | https://api-testnet.portuna.io | ptn_test_… |
| Mainnet: Ethereum, BSC | https://api.portuna.io | ptn_live_… |
See Test and live keys.
Authentication
Section titled “Authentication”Send your API key in every request:
curl "https://api-testnet.portuna.io/v1/balance" -H "Authorization: Bearer $PORTUNA_API_KEY"Without a key, or with an unknown or revoked one, the response is 401 unauthorized; for a disabled account it is
403 partner_disabled. GET /healthz and GET /v1/openapi.yaml need no key.
Formats
Section titled “Formats”- Requests: JSON with
Content-Type: application/json, up to 64 KiB; a sweep list up to 256 KiB. Unknown fields are an error,400 invalid_json, so a typo in a field name never goes unnoticed. - Amounts: strings with an integer in the token’s smallest units, such as
"1000000": wei for the native coin, 10⁻⁶ for USDT on Ethereum. Strings, because amounts outgrow the integers of many JSON parsers. - Addresses:
0x-hex in any case; responses give them checksummed (EIP-55). - Chains:
chain_id, the chain’s numeric id, such as11155111for Sepolia. - Times: RFC 3339, in UTC.
- Optional fields without a value are left out of responses.
GET /v1/sweeps, /v1/revocations, /v1/transactions, /v1/ledger, /v1/payouts and /v1/webhook/deliveries
return pages, newest first:
{ "items": [ … ], "next_cursor": "eyJ0Ijoi…" }limitsets the page size: up to 200, 50 by default.- Pass
next_cursorascursorto get the next page; on the last page it isnull. The cursor is opaque. - Rows added between your requests neither shift the pages nor repeat.
- Filters combine. Sweeps and revocations are also found by your
external_idand by the transaction that carried them:tx_hash, any hash it had, ortransaction_id.list_idgives the sweeps of a sweep list and the transactions it rode. - A bad parameter gets
400 invalid_query, with the parameter inmessage. - The SDKs go through the pages for you:
AllSweepsand the like in Go,allSweepsand the like in TypeScript.
Errors
Section titled “Errors”{ "error": { "code": "unknown_token", "message": "token must be \"native\", a listed ticker or its address, or the address of a token you added with POST /v1/tokens" } }Branch on code, which is stable; message is for people. Some codes carry details, such as the cause of a token’s
refusal in details.cause. Every code: Errors and retries.
Requests that create sweeps, sweep lists and revocations take an external_id to be safe to retry: see
Idempotency.
OpenAPI specification
Section titled “OpenAPI specification”- openapi.yaml: the OpenAPI 3.1 specification with English descriptions, for code generators and API tools.
GET /v1/openapi.yamlon the API serves the same specification as the running service knows it.