I'm currently working on a project where I use the 0x API on the Goerli network to swap tokens. I'm making an HTTP GET request using axios from a web application served from http://localhost:3000.

Here is a snippet of my code:

const host = 'https://goerli.api.0x.org';
const headers = {
  '0x-api-key': '[api-key]', 
const response = await axios
  .get(`${host}/swap/v1/quote?sellToken=ETH&buyToken=DAI&sellAmount=10000000`, {
  .catch(error => {
    throw new Error(`Failed to get quote: ${error.message}`);

When I try to execute this request, I encounter a CORS error stating that my 0x-api-key header is not allowed:

Access to XMLHttpRequest at 'https://goerli.api.0x.org/swap/v1/quote?sellToken=ETH&buyToken=DAI&sellAmount=10000000' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field 0x-api-key is not allowed by Access-Control-Allow-Headers in preflight response.

Given the error message, it seems the server's CORS policy does not allow the 0x-api-key header field. I've tried several methods to solve this, but none of them worked.

I have confirmed that the same request works on Mainnet. It seems to be an issue specific to Goerli.

I have also tried a variety of different token pairs, pairs that I know to have liquidity.

I understand that CORS is a browser-enforced policy to ensure the security of web applications, but I'm confused about why the 0x-api-key header is not allowed. Is this a setting on your server's end, or is there a way I can adjust my request to align with the server's CORS policy? Any guidance on how to address this issue would be greatly appreciated.

Thanks in advance for your help!

2 Answers 2


I found the solution for any who stumble across this. It turns out it happens when you include the API key when using Goerli. All I had to do was remove the API key.

The 0x documentation should really be updated on how to use testnet properly.


I spent a long time trying to figure out the format of the 0x API key line and add that in when using Goerli testnet. For anyone else who is looking the format is const headers = {'0x-api-key': 'paste-key-here' } which doesn't look anything like what was there const headers = {'0x-api-key: [api-key]'}; Also no mention of headers in the youtube tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.