curl -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '\''1'\'' day LIMIT 10",
"performance": "medium"
}'
import requests
url = "https://api.dune.com/api/v1/sql/execute"
headers = {
"X-DUNE-API-KEY": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
"performance": "medium"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.dune.com/api/v1/sql/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-DUNE-API-KEY': 'YOUR_API_KEY'
},
body: JSON.stringify({
sql: "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
performance: 'medium'
})
});
const data = await response.json();
console.log(data);
# Step 1: Execute SQL and get execution ID
EXECUTION_ID=$(curl -s -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{"sql": "SELECT * FROM dex.trades LIMIT 10", "performance": "medium"}' \
| jq -r '.execution_id')
# Step 2: Poll for completion
while true; do
STATE=$(curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/status" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
| jq -r '.state')
echo "State: $STATE"
[[ "$STATE" =~ (QUERY_STATE_COMPLETED|QUERY_STATE_FAILED|QUERY_STATE_CANCELLED) ]] && break
sleep 2
done
# Step 3: Get results
curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/results" \
-H "X-Dune-Api-Key: YOUR_API_KEY" | jq
{
"execution_id": "01HKZJ2683PHF9Q9PHHQ8FW4Q1",
"state": "QUERY_STATE_PENDING"
}
Executions and Results
Execute SQL
Execute raw SQL queries directly without needing to create a saved query first
POST
/
v1
/
sql
/
execute
curl -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '\''1'\'' day LIMIT 10",
"performance": "medium"
}'
import requests
url = "https://api.dune.com/api/v1/sql/execute"
headers = {
"X-DUNE-API-KEY": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
"performance": "medium"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.dune.com/api/v1/sql/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-DUNE-API-KEY': 'YOUR_API_KEY'
},
body: JSON.stringify({
sql: "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
performance: 'medium'
})
});
const data = await response.json();
console.log(data);
# Step 1: Execute SQL and get execution ID
EXECUTION_ID=$(curl -s -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{"sql": "SELECT * FROM dex.trades LIMIT 10", "performance": "medium"}' \
| jq -r '.execution_id')
# Step 2: Poll for completion
while true; do
STATE=$(curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/status" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
| jq -r '.state')
echo "State: $STATE"
[[ "$STATE" =~ (QUERY_STATE_COMPLETED|QUERY_STATE_FAILED|QUERY_STATE_CANCELLED) ]] && break
sleep 2
done
# Step 3: Get results
curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/results" \
-H "X-Dune-Api-Key: YOUR_API_KEY" | jq
{
"execution_id": "01HKZJ2683PHF9Q9PHHQ8FW4Q1",
"state": "QUERY_STATE_PENDING"
}
Minimum required API key scope:
ReadRun arbitrary SQL queries via API. This endpoint allows you to execute SQL directly without first creating a query object, perfect for dynamic analysis and automated workflows.
When executing arbitrary SQL queries (queries not saved in Dune), the
query_id in the response will always be 0. This is a placeholder value since these queries are not stored in the Dune database.Pricing
This endpoint is usage-based and consumes credits based on the computational resources used during execution.curl -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '\''1'\'' day LIMIT 10",
"performance": "medium"
}'
import requests
url = "https://api.dune.com/api/v1/sql/execute"
headers = {
"X-DUNE-API-KEY": "YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"sql": "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
"performance": "medium"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.dune.com/api/v1/sql/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-DUNE-API-KEY': 'YOUR_API_KEY'
},
body: JSON.stringify({
sql: "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
performance: 'medium'
})
});
const data = await response.json();
console.log(data);
# Step 1: Execute SQL and get execution ID
EXECUTION_ID=$(curl -s -X POST "https://api.dune.com/api/v1/sql/execute" \
-H "Content-Type: application/json" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
-d '{"sql": "SELECT * FROM dex.trades LIMIT 10", "performance": "medium"}' \
| jq -r '.execution_id')
# Step 2: Poll for completion
while true; do
STATE=$(curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/status" \
-H "X-Dune-Api-Key: YOUR_API_KEY" \
| jq -r '.state')
echo "State: $STATE"
[[ "$STATE" =~ (QUERY_STATE_COMPLETED|QUERY_STATE_FAILED|QUERY_STATE_CANCELLED) ]] && break
sleep 2
done
# Step 3: Get results
curl -s "https://api.dune.com/api/v1/execution/$EXECUTION_ID/results" \
-H "X-Dune-Api-Key: YOUR_API_KEY" | jq
{
"execution_id": "01HKZJ2683PHF9Q9PHHQ8FW4Q1",
"state": "QUERY_STATE_PENDING"
}
Headers
API Key for the service
Query Parameters
Alternative to using the X-Dune-Api-Key header
Body
*/*
ExecuteSQLRequest
Was this page helpful?