Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.opper.ai/llms.txt

Use this file to discover all available pages before exploring further.

This assistant searches the live web with Opper’s built-in web tool, then uses the JSON API to write a grounded answer that cites its sources. Two steps: search, then one structured call.
python app.py

You › What is Mistral’s largest open-weight model?

Tool › web_search(“Mistral largest open-weight model”)
→ 5 results from the web

Bot › Mistral’s largest open-weight model is Mistral Medium 3.5, a 128B-parameter model for reasoning, coding, and instruction-following.

sources: [“mindstudio.ai/blog/what-is-mistral-medium-3-5…”]

Search results go in, a typed answer with sources comes out.

The assistant

import os, requests
from pydantic import BaseModel, Field
from opperai import Opper

KEY = os.getenv("OPPER_API_KEY", "")
opper = Opper(http_bearer=KEY)

def web_search(query: str) -> list[dict]:
    r = requests.post(
        "https://api.opper.ai/v3/tools/web/search",
        headers={"Authorization": f"Bearer {KEY}"},
        json={"query": query},
    )
    r.raise_for_status()
    return r.json()["results"]

class Answer(BaseModel):
    answer: str = Field(description="A concise answer grounded in the search results.")
    sources: list[str] = Field(description="URLs of the results you actually used.")

def research(question: str):
    results = web_search(question)
    out = opper.call(
        name="answer-with-sources",
        instructions="Answer the question using only the provided search results. Cite the URLs you used in sources.",
        input={"question": question, "results": results},
        output_schema=Answer,
    )
    return out.json_payload

if __name__ == "__main__":
    data = research("What is Mistral's largest open-weight model?")
    print(data["answer"])
    print("Sources:", data["sources"])
Run it:
pip install opperai requests
export OPPER_API_KEY="your-api-key"
python app.py

How it works

  • Search. web_search calls Opper’s hosted web tool (POST /v3/tools/web/search) and returns a list of {title, url, snippet} results. No separate search API key to manage.
  • Answer. The JSON API call gets the question plus those results and returns a typed Answer. Because the output is schema-constrained, answer and sources come back clean, with no parsing.
  • Grounding. The model only sees the results you pass in, so it answers from the search rather than from memory. If a fact isn’t in the results, it can say so.
Pass more or fewer results to trade cost for coverage, and add an Observe rule that checks every answer actually cites a source.

What’s next

Calls

The JSON API basics behind the answer step.

Web search

The web tool’s full API reference.

Schemas

Shape the answer and sources however you like.

Observe

Score answers for grounding and citation quality.