Skip to main content

API Reference

Base URL: https://api.swapapi.dev

All responses use a consistent envelope format with success, data (or error), and timestamp fields.


GET /v1/swap/{chainId}

Returns a swap quote with executable transaction data. This is the core endpoint.

Path parameters

ParamTypeRequiredDescription
chainIdintegeryesEVM chain ID. See Supported Chains.

Query parameters

ParamTypeRequiredDefaultDescription
tokenInaddressyesToken to sell. Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native ETH/gas token.
tokenOutaddressyesToken to buy.
amountstringyesAmount to swap in the token's smallest unit (wei for ETH, 6-decimal units for USDC, etc). Must be a numeric string.
senderaddressyesAddress that will execute the swap transaction.
maxSlippagenumberno0.005Maximum allowed slippage as a decimal. 0.005 = 0.5%. Range: 0 to 1.
Address format

All address parameters must be a valid 0x-prefixed hex address: 0x followed by exactly 40 hex characters.

Example request

curl "https://api.swapapi.dev/v1/swap/8453?\
tokenIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&\
tokenOut=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&\
amount=1000000000000000000&\
sender=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045&\
maxSlippage=0.01"

Success response (200)

{
"success": true,
"data": {
"status": "Successful",
"tokenFrom": {
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"symbol": "ETH",
"name": "Ether",
"decimals": 18
},
"tokenTo": {
"address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"symbol": "USDC",
"name": "USD Coin",
"decimals": 6
},
"swapPrice": 2435.12,
"priceImpact": 0.0003,
"amountIn": "1000000000000000000",
"expectedAmountOut": "2435120000",
"tx": {
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"to": "0x011E52E4E40CF9498c79e329EBc29ed08c8B5abB",
"data": "0x2646478b...",
"value": "1000000000000000000",
"gasPrice": 30000000000,
"gas": "250000"
}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

Response fields

FieldTypeDescription
successbooleanAlways true for successful responses.
data.statusstringQuote status: "Successful" (full swap available), "Partial" (only part of the amount can be swapped), or "NoRoute" (no viable route found).
data.tokenFromobjectInput token info: address, symbol, name, decimals.
data.tokenToobjectOutput token info: address, symbol, name, decimals.
data.swapPricenumberExchange rate — units of output token per one input token.
data.priceImpactnumberEstimated price impact as a decimal (0.001 = 0.1%).
data.amountInstringInput amount in smallest token unit (echoed from request).
data.expectedAmountOutstringGuaranteed minimum output amount in the output token's smallest unit.
data.tx.fromstringSender address (echoed from request).
data.tx.tostringRouter contract address to send the transaction to.
data.tx.datastringEncoded calldata for the swap.
data.tx.valuestringNative token value to include. Non-zero when selling native ETH.
data.tx.gasPricenumberSuggested gas price in wei.
data.tx.gasstringEstimated gas limit.
timestampstringISO 8601 timestamp.

Error responses

All errors follow this format:

{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable description",
"details": {}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

400 — Validation Error

Returned when request parameters fail validation (missing required params, invalid address format, etc).

{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid request parameters",
"details": {
"issues": [
{
"code": "invalid_string",
"message": "Invalid",
"path": ["tokenIn"]
}
]
}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

400 — Unsupported Chain

Returned when the chain ID is not supported.

{
"success": false,
"error": {
"code": "UNSUPPORTED_CHAIN",
"message": "Chain 999 is not supported",
"details": {
"chainId": 999
}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

400 / 502 — Upstream Error

Returned when the routing engine encounters an error. 400 for client-side issues, 502 for upstream failures.

{
"success": false,
"error": {
"code": "UPSTREAM_ERROR",
"message": "Routing engine returned an error",
"details": {
"upstream": "No route found for the given pair"
}
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

429 — Rate Limited

{
"success": false,
"error": {
"code": "RATE_LIMIT",
"message": "Rate limit exceeded"
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

500 — Internal Error

{
"success": false,
"error": {
"code": "INTERNAL_ERROR",
"message": "Internal server error"
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

GET /health

Health check endpoint. Not rate limited.

Example request

curl "https://api.swapapi.dev/health"

Response (200)

{
"success": true,
"data": {
"status": "ok"
},
"timestamp": "2026-03-12T00:00:00.000Z"
}

GET /openapi.json

Returns the full OpenAPI 3.1.0 specification for the API. This is machine-readable and can be consumed directly by:

  • Swagger UI / Redoc for interactive documentation
  • OpenAI GPT Actions / function calling
  • LangChain API tools
  • Any OpenAPI-compatible code generator
curl "https://api.swapapi.dev/openapi.json"

A Swagger UI is also available at /docs.


GET /llms.txt

Returns a plain-text description of the API designed for LLM tool discovery. When an AI agent fetches this file, it gets everything it needs to construct valid API calls — endpoint URL, parameters, and examples — in a format optimized for language model consumption.

curl "https://api.swapapi.dev/llms.txt"

This follows the llms.txt convention for making APIs discoverable by AI agents.


Quick reference

Endpoint: GET https://api.swapapi.dev/v1/swap/{chainId}
Required params: tokenIn, tokenOut, amount, sender
Optional params: maxSlippage (default: 0.005)
Auth: None
Rate limit: 60 req/min per IP