> For the complete documentation index, see [llms.txt](https://docs.dexlab.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dexlab.space/developer-hub/token-and-swap-apis/swap-api.md). Agents can also search and read this documentation through its [MCP server](https://docs.dexlab.space/~gitbook/mcp).

# 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/`
  * *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/`
  * *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":{}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.dexlab.space/developer-hub/token-and-swap-apis/swap-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
