Skip to main content
This guide shows how to integrate Seltz as a search tool for OpenAI models. When the model needs to search for information, it will call your Seltz-powered function and use the results to generate informed responses.

Prerequisites

Installation

Setup

Set your API keys as environment variables:
Initialize both clients:

Define the Search Tool

Create a tool schema that describes the Seltz search function to OpenAI:

Using Chat Completions API

Here’s a complete example using OpenAI’s Chat Completions API with Seltz search:

How It Works

  1. User sends a message - The user asks a question that may require search
  2. OpenAI decides to search - The model determines if it needs external information
  3. Tool call is made - OpenAI returns a tool call with the search query
  4. Seltz executes search - Your code calls Seltz with the query
  5. Results sent back - Search results are added to the conversation
  6. Final response - OpenAI generates a response using the search results

Streaming Responses

For a better user experience, stream the final response:

Multi-Turn Conversations

Maintain conversation history for follow-up questions:

Error Handling

Handle Seltz errors gracefully so the model can respond appropriately:

Best Practices

The description helps OpenAI decide when to use the tool. Be specific about what the search returns and when it should be used.
More results mean more tokens. Use max_results to balance comprehensiveness with cost and latency.
Return error information as JSON so the model can inform the user or try alternative approaches.
Stream the final response so users see output immediately rather than waiting for the full response.

Next Steps

Anthropic Tool Calling

Integrate with Claude models.

Agno Framework

Build autonomous agents with Seltz.