Skip to main content
Exa is a web search API built for AI applications. It returns clean, ready-to-use page content with every result, making it easy to ground SambaNova model responses in current web data.

Prerequisites

Before starting, ensure you have:

Setup

Follow the steps below to install the required dependencies and configure your environment.
1

Install dependencies

Install the required SDKs for your preferred language.
pip install "exa-py>=2.0" openai python-dotenv
The Node.js examples use ES modules and top-level await. Save them with a .mjs extension (or set "type": "module" in your package.json).
2

Configure API keys

Create a .env file in your project directory:
SAMBANOVA_API_KEY=your-sambanova-api-key
EXA_API_KEY=your-exa-api-key
3

Search the web with Exa

Use Exa to retrieve relevant web content and highlights for your query.
from dotenv import load_dotenv
from exa_py import Exa
import os

load_dotenv()

exa = Exa(api_key=os.environ["EXA_API_KEY"])

results = exa.search(
    "latest developments in AI agents",
    type="auto",
    num_results=10,
    contents={"highlights": True},
)
4

Ground a SambaNova model with search results

Using the results from the previous step, format the Exa search results as context and pass them to a SambaNova-hosted model.
from dotenv import load_dotenv
from openai import OpenAI
import os

load_dotenv()

client = OpenAI(
    api_key=os.environ["SAMBANOVA_API_KEY"],
    base_url="https://api.sambanova.ai/v1",
)

context = "\n\n".join(
    f"Source: {result.url}\n{' '.join(result.highlights or [])}"
    for result in results.results
)

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=[
        {
            "role": "system",
            "content": "Using only the provided search results, write a short summary.",
        },
        {
            "role": "user",
            "content": f"Search results:\n\n{context}",
        },
    ],
)

print(response.choices[0].message.content)
5

(Optional) Enable tool calling with Exa

For agentic workflows, expose Exa search as a function tool so the model can decide when to search the web.
from dotenv import load_dotenv
from exa_py import Exa
from openai import OpenAI
import os
import json

load_dotenv()

exa = Exa(api_key=os.environ["EXA_API_KEY"])
client = OpenAI(
    api_key=os.environ["SAMBANOVA_API_KEY"],
    base_url="https://api.sambanova.ai/v1",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "exa_search",
            "description": "Search the web using Exa and return grounded results.",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string",
                        "description": "The search query.",
                    }
                },
                "required": ["query"],
            },
        },
    }
]

messages = [
    {"role": "user", "content": "What are the latest developments in AI agents?"}
]

response = client.chat.completions.create(
    model="MiniMax-M2.7",
    messages=messages,
    tools=tools,
)

if response.choices[0].finish_reason == "tool_calls":
    tool_call = response.choices[0].message.tool_calls[0]
    args = json.loads(tool_call.function.arguments)

    search_results = exa.search(
        args["query"],
        type="auto",
        num_results=5,
        contents={"highlights": True},
    )

    context = "\n\n".join(
        f"Source: {r.url}\n{' '.join(r.highlights or [])}"
        for r in search_results.results
    )

    messages.append(response.choices[0].message)
    messages.append({
        "role": "tool",
        "tool_call_id": tool_call.id,
        "content": context,
    })

    final_response = client.chat.completions.create(
        model="MiniMax-M2.7",
        messages=messages,
        tools=tools,
    )

    print(final_response.choices[0].message.content)

Search modes and freshness controls

Exa supports multiple search strategies:
Search typeBest for
autoRecommended. Best balance of quality and speed.
fastLowest-latency search experience.
deepMost comprehensive search coverage.
Use max_age_hours (Python) or maxAgeHours (Node.js) to control how recent the returned content must be. Setting this to 0 forces Exa to fetch only live content, while 24 permits results up to one day old.

Example use cases

Here are some common use cases this integration enables:
  • Ground chatbot responses with current web information
  • Build research assistants with source citations
  • Retrieve recent news and developments
  • Add web search capabilities to AI agents
  • Create retrieval-augmented generation (RAG) workflows without maintaining your own search infrastructure

Additional resources