Skip to content
NewWe build AI products for companies
Usefully
All articles

Guide

Give your app the live web: search, read, cite

Training data goes stale. Here's the pattern for answering from current sources, with citations: search the web, read the best pages, and answer from them.

· 2 min read · Usefully team


An AI assistant answers from what it learned during training. Ask about last week's release, today's price or a page it has never seen, and it either guesses or says it doesn't know. The fix is to hand it the sources: search the web, read the best pages, and have it answer from them.

Usefully covers the first two steps. Search and page reading use the same API key and the same balance, and every call shows up in your logs with its cost.

1. Search

POST /v1/search returns titles, URLs, short snippets and, when known, publish dates. Add include_content to get each page's main text in the same call, which is usually all you need.

curl https://api.usefully.info/v1/search \
  -H "Authorization: Bearer $USEFULLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "postgres 18 new features", "num_results": 5, "include_content": true}'

Useful options: freshness (day, week, month or year) for anything recent, and include_domains to search only sites you trust. Each result's content is up to 5,000 characters by default; raise it with max_content_chars (up to 50,000).

2. Read (when a snippet isn't enough)

If you already have URLs, or need a page in full, POST /v1/extract returns the main text of up to 10 pages per call, as Markdown, with the final_url after redirects. A page that can't be fetched comes back as failed and isn't billed.

curl https://api.usefully.info/v1/extract \
  -H "Authorization: Bearer $USEFULLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://example.com/release-notes"], "max_chars": 20000}'

3. Answer, with citations

Number the sources, put them in the prompt, and say to answer from them only. Building that prompt is plain string work:

import os, requests

KEY = os.environ["USEFULLY_API_KEY"]

def grounded_prompt(question: str) -> str:
    hits = requests.post(
        "https://api.usefully.info/v1/search",
        headers={"Authorization": f"Bearer {KEY}"},
        json={"query": question, "num_results": 5, "include_content": True},
        timeout=45,
    ).json()["results"]
    sources = "\n\n".join(
        f"[{i}] {h['title']} ({h['url']})\n{h.get('content') or h['snippet']}"
        for i, h in enumerate(hits, 1)
    )
    return (
        "Answer from the sources only. Cite them like [1]. "
        "Say so if they don't answer the question.\n\n"
        f"Question: {question}\n\nSources:\n{sources}"
    )

Send that prompt to whatever your app uses to write answers, and return the URLs alongside the reply.

Tips

  • Keep the prompt focused. Five good sources beat twenty mediocre ones.
  • Ask for "I don't know". Saying the answer must admit when the sources don't cover the question cuts down made-up answers.
  • Show the sources. Return the URLs with the answer so people can check them.
  • Use freshness for news. "freshness": "week" keeps old pages out of time-sensitive questions.

Full details are in the search guide and reading pages.

More articles

Get started

Your first request is five minutes away.

  • Top up from $1
  • No subscription, no minimum
  • Works with any HTTP client
  • Real people at support@usefully.info
Give your app the live web: search, read, cite · Usefully