How to Use AI tools and Unusual Whales API together
As part of our breakdown of the Unusual Whales API
🛏 JOIN EIGHT SLEEP WITH CODE WHALES FOR $350 OFF! 🛏
Hey all,
Nicholas from the Unusual Whales team, here! We’re going to spend one issue every week walking you through some trades of the week for free to help your trading!
In this issue, we’re going to cover how you can utilize artificial intelligence tools to interact with the Unusual Whales API! Sometimes, AI “hallucinates” endpoints that don’t exist, and this guide teaches you how to fix that!
How to Fix 404 Errors when Using AI Tools with the Unusual Whales API
If you are using an AI-based software development suite like Cursor, Windsurf, ChatGPT, or Claude and getting errors like “404 Not Found” or “Something went wrong” we have a quick fix for you.
The Problem
AI tools sometimes hallucinate API endpoints, which means they suggest URLs that do not actually exist.
How to Fix It
Visit https://api.unusualwhales.com/api/openapi
Copy all the text (use Ctrl+A because there are more than 13K lines)
Create a file named api_spec.yaml in your project
Paste the copied text into this file and save it
Tell your AI tool to only use endpoints from api_spec.yaml
Examples
Cursor
Let’s say we are starting from scratch in Cursor. The “setup” here was simply creating a directory for the project, then opening Cursor in that directory. I sent this generic prompt to build a trading app using the Unusual Whales API:
I would like to build a trading application in python using the Unusual Whales API
As you can see above, the AI hit us with two separate URLs (endpoints) that simply do not exist on Unusual Whales! Since these endpoints do not exist, running this script would result in several errors. So, let’s work through the steps from above, and fix this issue!
First, we navigate to https://api.unusualwhales.com/api/openapi and copy all the text with Ctrl+A. Next, we create an api_spec.yaml file in our trading app project:
Then we open the api_spec.yaml file and paste in all the copied text like this:
Finally, save the api_spec.yaml file.
We are now ready to prompt Cursor to fix the endpoints! I entered the following prompt into the “Agent” screen and the results were perfect (i.e. all non-existent endpoints corrected):
I added the file api_spec.yaml to this project that includes all available endpoints from the Unusual Whales API, can you review the code you have written and make sure it only accesses endpoints that exist?
And there we go! All endpoints displayed here are real; no more hallucinations!!
Before we get to another example of using AI to help with API processes, I want to tell you about Eight Sleep as it changed the way I sleep for the better.
Numerous neuroscientists like Andrew Huberman have already raved about it, but it goes without saying: my sleep has improved so much with Eight Sleep that even as a whale I cannot tell you how unusual it is. It helps you cool, heat, track and ultimately sleep better. There is no other product like it. Truly.
As a result, I partnered with Eight Sleep to get you guys a discount for a product I love. Head over to www.eightsleep.com/whales/ https://www.eightsleep.com/ca/whales/) and use the code WHALES to get $350 off your very own Pod 4 Ultra, which is customized to your sleep settings. If you sleep better, you'll likely trade better, too!
Join the warm waters at Eight Sleep, and focus on all trader's foundation: their sleep! Join here.
Now, let’s break down another example; this time using Windsurf.
Windsurf
In Windsurf we have a similar setup where the initial build resulted in hallucinated endpoints.
So, I first went on over to https://api.unusualwhales.com/api/openapi to copy all the text using CTRL+A then CTRL+C. Then, I created the api_spec.yaml file in my project, pasted the copied text from step 1 into the file, and saved it. Then, I told our friend Windsurf to use only endpoints from that api_spec.yaml file.
After following those same steps to create the api_spec.yaml file in the project, I was able to enter a similar prompt:
I saved the Unusual Whales API spec to the trading_app directory as api_spec.yaml, please review this file and correct all url routes in app.py that do not exist in the api_spec.yaml file
With the new prompt, and the correct endpoints being pulled from api_spec.yaml, we’ve got zero hallucinated endpoints! Now we can run our script.
Thank you as always for reading! REMEMBER!! You can find articles like this and MANY others about Options and the Unusual Whales Platform on the new Information Hub!!
And remember, you can join EIGHT SLEEP WITH CODE WHALES FOR $350 OFF!
NOTE: This post is not financial advice. The stock market is risky, and any trade or investment is expected to have some, or total, loss. Please do research before any trade. Do not use this information for investment decisions. Check terms on site for full terms. Agree to terms before considering this information.
NOTE: Unusual Whales is not responsible for any promotion or #ad. It does not verify the authenticity of the promotion or partnership, nor the merits of the individual promotion. Unusual Whales does not necessarily endorse or condone any one promotion. Unusual Whales does not advocate for any sponsor. Please do your own diligence and research before following any one promoted post. Do not consider a promotion of a post an advocacy for the sponsor of the post.