> For the complete documentation index, see [llms.txt](https://docs.squidrouter.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.squidrouter.com/api-and-sdk-integration/key-concepts/get-a-route.md).

# Get a route

{% hint style="info" %}
We recommend getting a new route or quote every 20 seconds to refresh prices.
{% endhint %}

{% tabs %}
{% tab title="SDK" %}

```typescript
// Set up parameters for swapping tokens and depositing into Radiant lending pool
const params = {
  fromAddress: signer.address,
  fromChain: arbitrumId,
  fromToken: usdcArbitrumAddress,
  fromAmount: amount,
  toChain: polygonId,
  toToken: nativeToken,
  toAddress: signer.address,
  slippage: 1,
  quoteOnly: false,
};

// Get the swap route using Squid SDK
const { route, requestId } = await squid!.getRoute(params);

```

You can then explore the route response. This includes all the information on your quote `route.estimate` and all the data needed to generate a transaction `route.transactionRequest`.
{% endtab %}

{% tab title="API" %}

```typescript
// Function to get the optimal route for the swap using Squid API
const getRoute = async (params: any) => {
  try {
    const result = await axios.post(
      "https://v2.api.squidrouter.com/v2/route",
      params,
      {
        headers: {
          "x-integrator-id": integratorId,
          "Content-Type": "application/json",
        },
      }
    );
    const requestId = result.headers["x-request-id"]; // Retrieve request ID from response headers
    return { data: result.data, requestId: requestId };
  } catch (error) {
    if (error.response) {
      console.error("API error:", error.response.data);
    }
    console.error("Error with parameters:", params);
    throw error;
  }
};

// Get the swap route using Squid API
const routeResult = await getRoute(params);
const route = routeResult.data.route;
const requestId = routeResult.requestId;
console.log("Calculated route:", route);
console.log("requestId:", requestId);
```

{% endtab %}

{% tab title="Widgets" %}
All Squid widgets will get a route when the user can entered all the necessary parameters.

Widgets refresh quotes every 20 seconds.
{% endtab %}
{% endtabs %}


---

# 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.squidrouter.com/api-and-sdk-integration/key-concepts/get-a-route.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.
