diff --git a/.changeset/gentle-keys-help.md b/.changeset/gentle-keys-help.md
new file mode 100644
index 0000000..7cfbc7f
--- /dev/null
+++ b/.changeset/gentle-keys-help.md
@@ -0,0 +1,5 @@
+---
+"sushi": patch
+---
+
+ApiKey param for the swap function
diff --git a/site/pages/api/errors/estimate-gas.mdx b/site/pages/api/errors/estimate-gas.mdx
new file mode 100644
index 0000000..70486bf
--- /dev/null
+++ b/site/pages/api/errors/estimate-gas.mdx
@@ -0,0 +1,21 @@
+# Estimate Gas
+
+This problem occurs when the gas estimation fails.
+
+Your client application did everything correctly. Unfortunately our API encountered a condition that resulted in this problem.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/estimate-gas|Estimate Gas Error|422|
+
+**Example of an estimate-gas
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/estimate-gas",
+ "title": "Estimate Gas Error",
+ "details": "string",
+ "status": 422,
+ "code": "422-02"
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/insufficient-allowance.mdx b/site/pages/api/errors/insufficient-allowance.mdx
new file mode 100644
index 0000000..e6dca39
--- /dev/null
+++ b/site/pages/api/errors/insufficient-allowance.mdx
@@ -0,0 +1,26 @@
+# Insufficient Allowance
+
+This problem occurs when the spender doesn't have sufficient allowance.
+
+Your client asked for an estimation of a swap in which the spender doesn't have sufficient allowance. This prevents the estimation from completing successfully.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/insufficient-allowance|Insufficient Allowance|422|
+
+**Example of an insufficient-allowance
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/insufficient-allowance",
+ "title": "Insufficient Allowance Error",
+ "details": "Spender has insufficent allowance",
+ "status": 422,
+ "code": "422-04",
+ "token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
+ "spender": "0x85cd07ea01423b1e937929b44e4ad8c40bbb5e71",
+ "sender": "0x19b3eb3af5d93b77a5619b047de0eed7115a19e7",
+ "allowance": "1000000",
+ "amount": "5000000"
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/insufficient-balance.mdx b/site/pages/api/errors/insufficient-balance.mdx
new file mode 100644
index 0000000..b6d6264
--- /dev/null
+++ b/site/pages/api/errors/insufficient-balance.mdx
@@ -0,0 +1,25 @@
+# Insufficient Balance
+
+This problem occurs when the spender doesn't have sufficient balance.
+
+Your client asked for an estimation of a swap in which the spender doesn't have sufficient balance. This prevents the estimation from completing successfully.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/insufficient-balance|Insufficient Bllowance|422|
+
+**Example of an insufficient-balance
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/insufficient-balance",
+ "title": "Insufficient Balance Error",
+ "details": "Spender has insufficent balance",
+ "status": 422,
+ "code": "422-03",
+ "token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
+ "sender": "0x19b3eb3af5d93b77a5619b047de0eed7115a19e7",
+ "balance": "1000000",
+ "amount": "5000000"
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/invalid-api-key.mdx b/site/pages/api/errors/invalid-api-key.mdx
new file mode 100644
index 0000000..f638e5e
--- /dev/null
+++ b/site/pages/api/errors/invalid-api-key.mdx
@@ -0,0 +1,21 @@
+# Invalid Api Key
+
+This problem occurs when the provided API key is invalid or missing.
+
+Your client application tried to access a resource that requires an API key, but the key was either invalid or not provided. Please check your API key and try again. It can be provided as a query parameter or in the authorization header.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/invalid-api-key|Invalid Api Key|401|
+
+**Example of an invalid-api-key
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/invalid-api-key",
+ "title": "Invalid or Missing API Key",
+ "details": "Invalid API key",
+ "status": 401,
+ "code": "401-01",
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/no-fresh-data.mdx b/site/pages/api/errors/no-fresh-data.mdx
new file mode 100644
index 0000000..5647b72
--- /dev/null
+++ b/site/pages/api/errors/no-fresh-data.mdx
@@ -0,0 +1,21 @@
+# No Fresh Data
+
+This problem occurs when the API does not have fresh data available.
+
+Your client application did everything correctly. Unfortunately our API encountered a condition that resulted in this problem.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/no-fresh-data|No Fresh Data|500|
+
+**Example of an no-fresh-data
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/no-fresh-data",
+ "title": "No Fresh Data Error",
+ "details": "Network 1 data timeout",
+ "status": 500,
+ "code": "500-02",
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/ratelimit-exceeded.mdx b/site/pages/api/errors/ratelimit-exceeded.mdx
new file mode 100644
index 0000000..c712fc1
--- /dev/null
+++ b/site/pages/api/errors/ratelimit-exceeded.mdx
@@ -0,0 +1,21 @@
+# Ratelimit Exceeded
+
+This problem occurs when the provided API key has exceeded its rate limit.
+
+Your client application tried to access a resource that requires an API key, but the key has exceeded its rate limit. Please try again later.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/ratelimit-exceeded|Ratelimit Exceeded|429|
+
+**Example of an ratelimit-exceeded
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/ratelimit-exceeded",
+ "title": "Rate Limit Exceeded",
+ "details": "API key rate limit exceeded",
+ "status": 429,
+ "code": "429-01",
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/errors/unauthorized.mdx b/site/pages/api/errors/unauthorized.mdx
new file mode 100644
index 0000000..5b3436a
--- /dev/null
+++ b/site/pages/api/errors/unauthorized.mdx
@@ -0,0 +1,21 @@
+# Unauthorized
+
+This problem occurs when the provided API key has blacklisted / not-whitelisted your IP address or origin.
+
+Your client application tried to access a resource that requires an API key, but the key has either blacklisted or not whitelisted your IP address or origin. Please check your API key and try again. It can be provided as a query parameter or in the authorization header.
+
+|**Type URI**|**Title**|**Status**|
+|---|---|---|
+|https://docs.sushi.com/api/errors/unauthorized|Unauthorized|403|
+
+**Example of an unauthorized
problem details:**
+
+```json
+{
+ "type": "https://docs.sushi.com/api/errors/unauthorized",
+ "title": "Unauthorized",
+ "details": "IP not whitelisted",
+ "status": 403,
+ "code": "403-01",
+}
+```
\ No newline at end of file
diff --git a/site/pages/api/swap.mdx b/site/pages/api/swap.mdx
index 8aff468..317f471 100644
--- a/site/pages/api/swap.mdx
+++ b/site/pages/api/swap.mdx
@@ -33,12 +33,16 @@ const maxSlippage = 0.005
// Sender
const sender = '0x' // replace with your own address
+// Api Key, get yours at https://sushi.com/portal
+const apiKey = "sushi_abcdefghijklmnopqr"
+
const { searchParams } = SWAP_API_URL
searchParams.set('tokenIn', inputCurrency)
searchParams.set('tokenOut', outputCurrency)
searchParams.set('amount', amount.toString())
searchParams.set('maxSlippage', maxSlippage.toString())
searchParams.set('sender', sender)
+searchParams.set('apiKey', apiKey)
// Make call to API
console.log(SWAP_API_URL.toString())
diff --git a/site/pages/sdk/installation.mdx b/site/pages/sdk/installation.mdx
index 1f5e569..c263700 100644
--- a/site/pages/sdk/installation.mdx
+++ b/site/pages/sdk/installation.mdx
@@ -37,7 +37,8 @@ If you're not using a package manager, you can also use Sushi via an ESM-compati
tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
tokenOut: '0x6B3595068778DD592e39A122f4f5a5cF09C90fE2',
amount: 1000000000000000000n,
- maxSlippage: 0.005
+ maxSlippage: 0.005,
+ apiKey: "sushi_abcdefghijklmnopqr"
})
console.log(swap)
diff --git a/src/api/swap.ts b/src/api/swap.ts
index 51e3d09..e115d43 100644
--- a/src/api/swap.ts
+++ b/src/api/swap.ts
@@ -38,6 +38,7 @@ export type SwapRequest = {
override?: boolean
facade?: boolean
validate?: boolean
+ apiKey?: string
}
function swapResponseSchema(simulate?: Simulate) {
@@ -157,6 +158,10 @@ export async function getSwap<
url.searchParams.append('facade', params.facade.toString())
}
+ if (params.apiKey !== undefined) {
+ url.searchParams.append('apiKey', params.apiKey)
+ }
+
const res = await fetch(url.toString(), options)
if (!res.ok) {