# Swap API

## API Reference <a href="#v6-api-reference" id="v6-api-reference"></a>

[Dexlab](https://www.dexlab.space) Swap API is completely free and offers a highly intuitive and secure **REST API**.

As a powerful aggregator integrating various DEXs (Decentralized Exchanges) within the Solana ecosystem, Dexlab partners with the trusted global exchange, [**OKX**](https://www.okx.com/), to provide a stable and efficient trading environment.

Developers and project teams can leverage Dexlab Swap API to easily access liquidity, optimize trading routes, and experience cost savings with high trading performance.

{% hint style="success" %}
The Open API is freely accessible with no restrictions. However, it is subject to a rate limit of 2 request per second (RPS) per IP, and the referral fee can be set up to a maximum of 3% (100 bps).

[**Dexlab API Key Request**](https://forms.gle/pnuAjVNsM8Mm6LSg7)
{% endhint %}

## API Endpoint

All APIs are free to use, but the Pro API requires an API key(**Free**) issuance.

* Open API: `https://open-api.dexlab.space/`&#x20;
  * *There is a rate limit of 1 RPS. If you need more, get a free API key.*
* Pro API( API key required ): `https://pro-api.dexlab.space/`&#x20;
  * *The rate limit is increased and free.*

## Token Swap

{% hint style="info" %}
When using the Open API endpoint, the x-api-key is not required.
{% endhint %}

## POST /dex/swap

>

```json
{"openapi":"3.0.1","info":{"title":"Dexlab Public OpenAPI","version":"1.0"},"servers":[{"url":"https://open-api.dexlab.space"}],"paths":{"/dex/swap":{"post":{"operationId":"DexSwapController_dexSwap","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DexSwapRequestBody"}}},"required":true},"responses":{"200":{"description":"200 response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MODELbfa867"}}}},"400":{"description":"400 response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommonResponseError"}}}},"500":{"description":"500 response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommonResponseError"}}}}}}}},"components":{"schemas":{"DexSwapRequestBody":{"required":["amount","fromTokenAddress","slippageBps","toTokenAddress","userWalletAddress"],"type":"object","properties":{"userWalletAddress":{"type":"string","description":"The wallet address of the user initiating the swap."},"amount":{"type":"string","description":"The amount to swap. Must include precision (e.g., `1.00 USDT` -> `1000000`, `1.00 SOL` -> `1000000000`)."},"fromTokenAddress":{"type":"string","description":"The public key of the token to swap from."},"toTokenAddress":{"type":"string","description":"The public key of the token to swap to."},"slippageBps":{"maximum":10000,"minimum":0,"type":"number","description":"The maximum acceptable slippage in bps (basis points). Default is 500 (5%)."},"referrerWalletAddress":{"type":"string","description":"Optional wallet address to receive referrer fees."},"referrerFeeBps":{"maximum":300,"minimum":0,"type":"number","description":"Optional referrer fee in bps (basis points). Range: 0-300 for Open API, For Pro API, the limit varies depending on the contract."}}},"MODELbfa867":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/DexSwapResponse"}}},"DexSwapResponse":{"required":["bestRouter","fromTokenAddress","fromTokenAmount","maxSpendAmount","minReceiveAmount","requestAmount","requester","slippage","toTokenAddress","toTokenAmount","tx"],"type":"object","properties":{"bestRouter":{"description":"The most optimal router for the given swap operation, including the best path and associated costs.","allOf":[{"$ref":"#/components/schemas/DexSwapRouterResponse"}]},"requester":{"type":"string","description":"The wallet address of the requester."},"fromTokenAddress":{"type":"string","description":"The public key of the token being swapped from."},"toTokenAddress":{"type":"string","description":"The public key of the token being swapped to."},"fromTokenAmount":{"type":"string","description":"The input amount of a token to be sold"},"toTokenAmount":{"type":"string","description":"The resulting amount of a token to be bough"},"maxSpendAmount":{"type":"string","description":"The maximum amount of a token to sell when the price reaches the upper limit of slippage"},"minReceiveAmount":{"type":"string","description":"The minimum amount of a token to buy when the price reaches the upper limit of slippage"},"slippage":{"type":"string","description":"The allowed slippage in bps for the transaction."},"requestAmount":{"type":"string","description":"The requested amount for the swap."},"tx":{"type":"string","description":"Base58-encoded transaction command for signing and submission."}}},"DexSwapRouterResponse":{"required":["router","subRouters"],"type":"object","properties":{"router":{"type":"string","description":"The name of the best router used for the swap."},"subRouters":{"type":"array","description":"A list of sub-routers with details about routing paths.","items":{"$ref":"#/components/schemas/SubRouterResponse"}}}},"SubRouterResponse":{"required":["fromTokenAddress","protocol","toTokenAddress"],"type":"object","properties":{"protocol":{"type":"array","description":"The protocol used in this sub-router, including its name and contribution percentage.","items":{"$ref":"#/components/schemas/RouterProtocolResponse"}},"fromTokenAddress":{"type":"string","description":"The public key of the token being swapped from in this sub-routing operation."},"toTokenAddress":{"type":"string","description":"The public key of the token being swapped to in this sub-routing operation."}}},"RouterProtocolResponse":{"required":["name","percent"],"type":"object","properties":{"name":{"type":"string","description":"The name of the protocol"},"percent":{"type":"string","description":"The contribution percentage of this protocol"}}},"CommonResponseError":{"type":"object","properties":{}}}}}
```
