Overview
Fireworks AI hosts open models such as DeepSeek, Kimi, GLM, and Qwen behind an OpenAI-compatible API. This guide gives a Fireworks model asearch tool backed by the TinyFish Search API, so it can answer questions about current events and cite its sources.
The example is a single file, in Python or TypeScript.
How It Works
1
Send the question with a tool definition
Your code sends the question to a Fireworks model through its chat completions API, with a
search tool definition.2
The model calls the tool
The model returns a tool call with a search
query and a purpose, plus an optional domain_type.3
Your code runs TinyFish Search
Your code sends those arguments to
GET https://api.search.tinyfish.ai.4
Return the results
The top five results go back to the model as a
tool message.5
The model answers
The model writes an answer with its sources linked inline. The example caps the loop at five model calls.
Before You Start
1
Get your API keys
Create a Fireworks key at app.fireworks.ai/settings/users/api-keys and a TinyFish key at agent.tinyfish.ai/api-keys. Store both in your environment:
2
Install dependencies
You need Python 3.10+ or Node.js 22.18+.The TypeScript example uses top-level
await, so set "type": "module" in your package.json.Build the Tool
Save this asmain.py or main.ts:
What Each Search Looks Like
The model callssearch with arguments like these:
domain_type: "news", each result also includes publisher and date.
Run It
Key Choices
Tips
-
Pick a model that supports function calling. Any of them work. List them with:
- Append the assistant message unchanged. That carries its tool calls and reasoning context into the next request.
-
Cap the loop. Some models keep refining their searches. On the last call, disable tools and add a message telling the model to answer. With
tool_choice: "none"alone, DeepSeek returns an empty message. -
Return errors to the model. Failed or timed-out searches and malformed tool arguments go back as an
{"error": ...}tool result, so the model can retry or say it couldn’t search instead of the program crashing. -
Use
domain_type: "news"for recent events, andresearch_paperfor academic papers. - Treat results as untrusted. Search snippets are third-party content and can contain prompt injection. The system prompt tells the model never to follow instructions found in them.
- Collect source URLs in your code if you need a guaranteed source list. Inline links are a prompt convention.
Costs
You pay Fireworks per token. TinyFish Search is free up to 12,000 requests per day. Beyond that, requests need a positive wallet balance.Next Steps
Search API Reference
Every Search parameter you can expose to the model
Fetch API
Add a second tool that reads full pages
MCP Integration
Connect TinyFish to MCP-compatible clients
Fireworks Function Calling
Fireworks’ tool calling guide