Prerequisites
- Anthropic API key (Get one here)
- Seltz API key (Get one here)
Installation
Setup
Set your API keys as environment variables:Define the Search Tool
Create a tool schema that describes the Seltz search function to Claude:Using the Messages API
Here’s a complete example using Anthropic’s Messages API with Seltz search:How It Works
- User sends a message - The user asks a question that may require search
- Claude decides to search - The model determines if it needs external information
- Tool use is returned - Claude returns a
tool_useblock with the search query - Seltz executes search - Your code calls Seltz with the query
- Results sent back - Search results are sent as a
tool_result - Final response - Claude generates a response using the search results
Streaming Responses
Stream the final response for better user experience:Multi-Turn Conversations
Maintain conversation history for follow-up questions:Error Handling
Handle Seltz errors gracefully so Claude can respond appropriately:Best Practices
Write clear tool descriptions
Write clear tool descriptions
Claude uses the description to decide when to use the tool. Be explicit about what information the search provides and when it should be used.
Limit results appropriately
Limit results appropriately
More results mean more tokens and higher costs. Use
max_results to balance comprehensiveness with efficiency.Handle errors gracefully
Handle errors gracefully
Return error information as JSON so Claude can inform the user or suggest alternatives.
Use streaming for better UX
Use streaming for better UX
Stream the final response so users see output immediately rather than waiting for the complete response.
Next Steps
OpenAI Tool Calling
Integrate with OpenAI models.
Agno Framework
Build autonomous agents with Seltz.