Using Claude’s “Tool Use” Feature with Exa Search Integration.
Prerequisites and installation
anthropic
library to perform Claude API calls and completionsexa_py
library to perform Exa searchrich
library to make the output more readableANTHROPIC_API_KEY
and EXA_API_KEY
Be safe with your API keys. Make sure they are not hardcoded in your code or added to a git repository to prevent leaking them to the public.You can create an
.env
file in the root of your project and add the following to it:.env
file to your .gitignore
file if you have one.Understanding Claude's Tool Use Feature
exa_search
function we define.Use Exa Search as Claude tool
SYSTEM_MESSAGE
, which explains to Claude what it is supposed to do:exa_search
function that will call Exa’s search_and_contents
function with the query:main
function to bring it all together, and handle the user input and interaction with Claude:Full code
Running the code
claude_search.py
, and make sure the .env
file containing the API keys we previously created is in the same directory as the script.Then run the script using the following command from your terminal: