Build Transaction
curl --request GET \
--url https://api.jup.ag/swap/v2/build \
--header 'x-api-key: <api-key>'import requests
url = "https://api.jup.ag/swap/v2/build"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.jup.ag/swap/v2/build', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.jup.ag/swap/v2/build",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.jup.ag/swap/v2/build"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.jup.ag/swap/v2/build")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.jup.ag/swap/v2/build")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"inputMint": "<string>",
"outputMint": "<string>",
"inAmount": "<string>",
"outAmount": "<string>",
"otherAmountThreshold": "<string>",
"swapMode": "<string>",
"slippageBps": 123,
"priceImpactPct": "<string>",
"routePlan": [
{
"swapInfo": {
"ammKey": "<string>",
"label": "<string>",
"inputMint": "<string>",
"outputMint": "<string>",
"inAmount": "<string>",
"outAmount": "<string>"
},
"percent": 123,
"bps": 123,
"usdValue": 123
}
],
"computeBudgetInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"setupInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"swapInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"cleanupInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"otherInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"tipInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"addressesByLookupTableAddress": {},
"transactionVersion": 0,
"computeUnitPrice": "<string>",
"blockhashWithMetadata": {
"blockhash": [
123
],
"lastValidBlockHeight": 123,
"fetchedAt": {
"secs_since_epoch": 123,
"nanos_since_epoch": 123
}
}
}{
"error": "<string>"
}Metis (Onchain Router)
Build Transaction
Get a swap quote with raw instructions for building custom transactions
GET
/
build
Build Transaction
curl --request GET \
--url https://api.jup.ag/swap/v2/build \
--header 'x-api-key: <api-key>'import requests
url = "https://api.jup.ag/swap/v2/build"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.jup.ag/swap/v2/build', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.jup.ag/swap/v2/build",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.jup.ag/swap/v2/build"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.jup.ag/swap/v2/build")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.jup.ag/swap/v2/build")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"inputMint": "<string>",
"outputMint": "<string>",
"inAmount": "<string>",
"outAmount": "<string>",
"otherAmountThreshold": "<string>",
"swapMode": "<string>",
"slippageBps": 123,
"priceImpactPct": "<string>",
"routePlan": [
{
"swapInfo": {
"ammKey": "<string>",
"label": "<string>",
"inputMint": "<string>",
"outputMint": "<string>",
"inAmount": "<string>",
"outAmount": "<string>"
},
"percent": 123,
"bps": 123,
"usdValue": 123
}
],
"computeBudgetInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"setupInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"swapInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"cleanupInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"otherInstructions": [
{
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
}
],
"tipInstruction": {
"programId": "<string>",
"accounts": [
{
"pubkey": "<string>",
"isWritable": true,
"isSigner": true
}
],
"data": "<string>"
},
"addressesByLookupTableAddress": {},
"transactionVersion": 0,
"computeUnitPrice": "<string>",
"blockhashWithMetadata": {
"blockhash": [
123
],
"lastValidBlockHeight": 123,
"fetchedAt": {
"secs_since_epoch": 123,
"nanos_since_epoch": 123
}
}
}{
"error": "<string>"
}Authorizations
Get API key via https://developers.jup.ag/portal
Query Parameters
- Comma-separated list of DEXes to restrict routing to.
- Labels are case sensitive (
SolFi, notsolfi). An unrecognised label is not a validation error: it returns400 {"error": "No routes found"}, indistinguishable from a pair with no liquidity. - Mutually exclusive with excludeDexes. Passing both returns
400 {"error": "dexes and excludeDexes are mutually exclusive"}. - Full list of DEXes here using the
/program-id-to-labelendpoint.
Target maximum transaction size in bytes, leaving room for your own instructions.
- Sizing is deterministic, not an estimate: Metis builds and serializes the route to measure it. The swap it returns always fits your budget.
- Counts the bare swap only. Anything you add on top is not counted, so your final transaction can still exceed it: request parameters (
payer,feeAccount,tipAmount, destination accounts, close authority, cashback), your own instructions, extra signers, and your own lookup tables. - Set the budget below 1232 to leave room, then serialize your final transaction and lower
maxBytesfurther if it still exceeds 1232. As a rough guide, each added account costs 1 byte if in your lookup table else 32, and each extra signer about 96 bytes. - v0 only (400 with
transactionVersion=1).
Required range:
1 <= x <= 1232The Solana transaction version to build for, "0" or "1". Defaults to "0".
"1" returns v1 instructions: computeBudgetInstructions is empty and addressesByLookupTableAddress is {} (v1 inlines accounts, no lookup tables). Set the compute budget, including the returned computeUnitPrice, on the message config. Build with a v1-capable SDK (@solana/kit v8 or later).
Available options:
0, 1 Response
Quote with raw swap instructions
Was this page helpful?
