Skip to main content
This guide explains how to handle errors when using Sim APIs, including common error codes, troubleshooting steps, and code examples for proper error handling.

Errors vs. Warnings

Sim APIs distinguish between errors and warnings:
  • Errors indicate that the request failed and could not be fulfilled. The API returns an error response with an HTTP 4xx or 5xx status code.
  • Warnings indicate non-fatal issues where the request was partially fulfilled. The API returns a successful HTTP 200 response with data, but includes a warnings array to inform you about issues that occurred.

When Warnings Occur

Warnings are currently used when you request data for specific chains via the chain_ids parameter and some of those chains are not supported. For example:
  • If you request ?chain_ids=1,9999,10 and chain 9999 is not supported, the API will return data for chains 1 and 10, plus a warning about chain 9999.

Warning Response Format

When warnings are present, they appear in a warnings array within the successful (HTTP 200) response:
{
  "wallet_address": "0x37305b1cd40574e4c5ce33f8e8306be057fd7341",
  "balances": [...],
  "warnings": [
    {
      "code": "UNSUPPORTED_CHAIN_IDS",
      "message": "Some requested chain_ids are not supported. Balances are returned only for supported chains.",
      "chain_ids": [9999, 77777777777],
      "docs_url": "https://docs.sim.dune.com/evm/supported-chains"
    }
  ]
}
Each warning includes:
  • code: A machine-readable warning code (e.g., UNSUPPORTED_CHAIN_IDS)
  • message: A human-readable description of the warning
  • chain_ids: The list of chain IDs that caused this warning (for chain-related warnings)
  • docs_url: A link to relevant documentation for more information

Error Response Format

Authentication, rate limiting, and quota enforcement errors return JSON with an error field:
{
  "error": "invalid API Key"
}
All other errors return JSON with a message field:
{
  "message": "Internal server error"
}
A few endpoints (EVM Transactions, Activity, Token Info) return errors as plain text with no JSON wrapper. Check the error responses documented on each endpoint’s page for the exact format.
When handling errors programmatically, check for both "error" and "message" fields in the response body.

Common Error Codes

HTTP StatusDescriptionTroubleshooting
400Bad requestVerify the address format and other parameters in your request
401Invalid or missing API keyCheck that you’re including the correct API key in the X-Sim-Api-Key header
402Quota limit exceededYour request would exceed your compute unit quota. Contact sales@dune.com to upgrade your plan
403ForbiddenYour API key does not have Sim API permissions. Check your key’s assigned permissions
404Resource not foundVerify the endpoint URL and resource identifiers
405Method not allowedThe URL path is valid but the HTTP method is not supported. Use the correct method (e.g. GET)
429Too many requestsImplement backoff strategies and consider upgrading your plan if you consistently hit limits
500Internal server errorRetry the request after a short delay; if persistent, contact support
502Bad gatewayThe service is temporarily unreachable. Retry the request after a short delay
503Service unavailableThe service is temporarily in a retry state. Retry after a short delay

Handling Warnings in Code

When processing API responses, check for the warnings array to be notified of non-fatal issues:
const response = await fetch('https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045?chain_ids=1,9999,10', {
  headers: {'X-Sim-Api-Key': 'YOUR_API_KEY'}
});

const data = await response.json();

// Check for warnings
if (data.warnings && data.warnings.length > 0) {
  data.warnings.forEach(warning => {
    if (warning.code === 'UNSUPPORTED_CHAIN_IDS') {
      console.warn(`Warning: Chains ${warning.chain_ids.join(', ')} are not supported.`);
      console.warn(`See: ${warning.docs_url}`);
    }
  });
}

// Process the data that was successfully returned
console.log(`Found ${data.balances.length} balances`);

Handling Errors in Code

Here are examples of how to properly handle errors in different programming languages:
fetch('https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045', {
  method: 'GET', 
  headers: {'X-Sim-Api-Key': 'YOUR_API_KEY'}
})
  .then(async response => {
    if (!response.ok) {
      // Read response as text first, then try to parse as JSON.
      // Some endpoints return JSON errors, others return plain text.
      const text = await response.text();
      let errorMessage;
      try {
        const err = JSON.parse(text);
        errorMessage = err.error || err.message;
      } catch {
        errorMessage = text;
      }
      throw new Error(`API error (${response.status}): ${errorMessage || response.statusText}`);
    }
    return response.json();
  })
  .then(data => {
    console.log('Success:', data);
  })
  .catch(err => {
    console.error('Error:', err);
  });

Best Practices for Error Handling

  1. Always check for errors: Don’t assume API calls will succeed.
  2. Use HTTP status codes: Rely on HTTP status codes rather than parsing error message strings for programmatic decisions.
  3. Implement retry logic with backoff: For transient errors (like rate limits or server errors), implement exponential backoff.
  4. Provide meaningful error messages: Transform API error responses into user-friendly messages.
  5. Log errors for debugging: Maintain detailed logs of API errors for troubleshooting.
  6. Implement fallbacks: When possible, have fallback behavior when API calls fail.

Debugging Tips

If you’re experiencing persistent errors:
  1. Verify your API key: Ensure it’s valid and has the necessary permissions.
  2. Check request format: Validate that your request parameters match the API specifications.
  3. Inspect full error responses: The error message often contains specific details about what went wrong.
  4. Monitor your usage: Check if you’re approaching or exceeding rate limits.
  5. Test with cURL: Isolate issues by testing the API directly with cURL:
    curl -v -X GET "https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045" \
         -H "X-Sim-Api-Key: YOUR_API_KEY"
    

Need More Help?

If you’re still experiencing issues after following these guidelines, please reach out through our support channels.