Zarif Automates

How to Build an AI Research Assistant Using ChatGPT API

ZarifZarif
||Updated September 3, 2026

Most "AI research assistants" you see online are a single ChatGPT prompt with extra steps. A real one searches the live web, reads the sources, cites them, and remembers what you asked yesterday. I have built three different versions of this for clients and the playbook is finally clean. Here is the architecture, the API endpoints, the cost math, and the failure modes.

Definition

An AI research assistant is a software agent that takes a research question, searches authoritative sources, summarizes the findings with citations, and stores the results so you can build on them across sessions.

TL;DR

Why you should build this instead of using Perplexity

At the time of this update, Perplexity Pro is $20 per month and it is excellent. So why build your own? Three reasons. First, you control the source list, so you can restrict to your industry's primary sources and skip the SEO sludge. Second, you control how research is stored and connected to your systems. Third, you can measure model, search, storage, and verification costs per query instead of accepting a bundled product. A custom build is not automatically cheaper once engineering and maintenance are included.

The bar for "worth building" is whether you run more than 50 research queries a week and care about provenance. If you do, every hour you save compounds.

The architecture in plain English

The assistant has six moving parts:

  1. A query parser that classifies the question (factual, comparison, summarization, opinion)
  2. A search layer that hits the live web through Brave or Tavily
  3. A fetcher that pulls the actual page content, not just titles
  4. A synthesizer that uses a current model selected for the required quality and cost to write the answer with citations
  5. A memory layer backed by a vector database for prior research
  6. An output formatter that returns markdown with linked sources

That memory layer is the difference between a toy and a tool. Without it, you are just running a fancier Google search.

Step 1: Pick your model and your search provider

For OpenAI, the September 2026 shortlist begins with the current GPT-5.6 family. The official API price table lists short-context standard rates per 1 million tokens of $0.20 input and $1.20 output for GPT-5.6 Luna, $2 input and $12 output for Terra, and $4 input and $20 output for Sol. Start with Luna for extraction and routine synthesis, then test Terra or Sol only where your evaluation set shows a material quality gain. Recheck the table before deployment because models, context bands, and promotional rates change.

For search, the shortlist:

I would start a cost-sensitive build with GPT-5.6 Luna plus Tavily basic search, then benchmark Brave and OpenAI hosted search against the same known-answer set. Source coverage, citation accuracy, latency, and total verified-answer cost matter more than the headline request price.

Step 2: Set up your OpenAI Responses API call

The Responses API is the recommended default for new builds. OpenAI's migration guide confirms that the Assistants API shut down on August 26, 2026 and directs new integrations to Responses. The endpoint is POST https://api.openai.com/v1/responses. Your minimum payload looks like this:

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-5.6-luna",
    input=[
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": user_query}
    ],
    tools=[{"type": "web_search"}]
)

print(response.output_text)

The hosted web_search tool lets the model call OpenAI's hosted search directly, which is the simplest path. If you want full control over sources or budget, skip the built-in tool and call Tavily or Brave yourself.

Tip

Use a documented model snapshot when the selected model offers one, and record the exact model returned by the API in your evaluation logs. Do not invent a dated model slug: confirm available aliases and snapshots in the current model documentation before pinning.

Step 3: Write the system prompt that forces citations

This is the prompt I run in production, with names changed:

You are a senior research analyst. For every claim you make, you must
cite a source URL in markdown link format. If a source does not directly
support a claim, do not make the claim. If you cannot find authoritative
sources for a question, say "I do not have a confident answer" rather
than guessing. Output as markdown with an H2 "Sources" section at the end.

Three details matter. "Directly support" forces a tighter relationship between claim and evidence. The explicit "do not have a confident answer" escape hatch gives the system a valid abstention path. The Sources section is an audit trail, but it is not proof until the linked pages are fetched and checked.

Step 4: Wire in the vector memory layer

Without memory, your assistant is amnesiac. You have three viable paths in 2026:

I default to pgvector because it is a single Postgres extension and you avoid another vendor.

The flow:

  1. After every research session, embed the question and final answer with a supported embedding model priced from the current API table
  2. Store the embedding plus the raw text in a research_log table
  3. On every new query, search the table for top 3 semantically similar prior queries
  4. Inject those into the system prompt as "you previously researched..."

This is roughly 30 lines of code and it transforms the assistant from a search wrapper into a research partner.

Get 25 fill-in-the-blank prompts for useful, reviewable work.

Step 5: Add the citation verifier

Models lie about citations. They invent URLs. They quote pages that say the opposite. You need a verifier that fetches each cited URL, checks the status code, and ideally checks the cited claim against the page content.

The basic version makes a normal GET request for every cited URL, rejects missing pages and homepage redirects, and records protected-site responses for browser verification. HEAD alone is unreliable on some documentation and publisher sites.

The stronger version fetches each page, extracts the relevant text, and runs a claim-evidence check that can return supported, contradicted, or insufficient evidence. Price this from measured tokens and calls; do not promise that a second model eliminates fabrication.

Step 6: Choose your interface

You have three viable options:

  • Slack bot — best for team use. Use the Bolt SDK and post threaded responses.
  • CLI tool — best for solo developers. A Python script with typer is 50 lines.
  • Web app — best for sharing with non-technical users. Next.js plus the Vercel AI SDK gets you a streaming chat UI in an afternoon.

I run mine as a Slack slash command (/research) because that is where my team already lives. Context switching is the enemy.

Step 7: Set rate limits and a daily budget

The fastest way to bankrupt a side project is to leave the API key unprotected. Hard rules:

  1. Configure the available project budget alerts and usage limits in the provider dashboard, then enforce a hard application-side limit
  2. Wrap every call in a per-user token bucket — I use 50 queries per day per user
  3. Log every request with model, tokens, and cost to a Postgres table for audit
  4. Alert via webhook if daily spend exceeds $5

Provider billing dashboards are not an application-side control, so do not rely on them as your only safety net.

Warning

Never expose your OpenAI API key in a frontend. Always proxy through a backend that you control. Browser-side keys get scraped within hours of going public — this is not theoretical.

Step 8: Test on a known-answer set before shipping

Build a representative evaluation set where you already know the right answer and source. Run it before releases and on a regular cadence, tracking claim accuracy, citation support, abstention behavior, latency, and cost. Set pass thresholds from the risk of the use case rather than adopting a universal question count or accuracy floor.

I keep mine in a Google Sheet with columns for question, expected answer, model used, actual answer, and pass-fail. Five minutes a week to maintain.

What this costs in production

For a transparent example, take one user running 100 queries a day for 30 days, with one Tavily basic search and an average of 3,000 model-input plus 1,000 model-output tokens per query. At the cited September 2026 GPT-5.6 Luna and Tavily rates, 3,000 queries model to $5.40 for model tokens plus $24 for search, or $29.40 before verification calls, storage, hosting, retries, and engineering. Real research queries often use multiple searches and much more retrieved context, so meter the deployed workload rather than copying this scenario.

Compare the fully loaded monthly cost with Perplexity Pro's current $20 individual plan and the value of custom source controls, storage, integrations, and governance. A custom system wins when those controls justify its build and operating cost—not merely because token arithmetic looks cheap.

Common pitfalls I have hit personally

The model sometimes returns sources behind paywalls. Filter against a blocklist or your readers will hate you. The model occasionally cites the URL of the search result page instead of the actual source. Strip those in post-processing. Some sources rate-limit aggressively when fetched at scale. Add a 1-second random jitter between fetches.

FAQ

What is the cheapest way to build an AI research assistant?

Start with GPT-5.6 Luna and one search provider, then meter the real workload. At the cited September 2026 rates, the article's 3,000-query example is $29.40 for model tokens plus one Tavily basic search per query, before verification, storage, hosting, retries, and engineering. Brave's search endpoint is priced per 1,000 requests and OpenAI hosted search adds its own call and retrieved-token costs.

Can I build this without writing code?

Partially. n8n or Make.com can wire together OpenAI, Tavily, and a vector store with no code, and you can ship a usable assistant in a day. You will hit limits on the citation verifier and the eval set, where custom code is faster than visual nodes.

How do I prevent the assistant from hallucinating sources?

Three layers. Force the model to cite URLs in the system prompt. Run a verifier that HEAD-requests every URL and drops 404s. For high-stakes use, run a second LLM call that checks each cited claim against the actual page content.

Do I need a vector database for a simple assistant?

No, you can ship a v1 without memory. But once you cross 20 queries a week, the lack of memory becomes painful because you re-research the same topics. pgvector on existing Postgres is the lowest-friction upgrade path.

Should I use the OpenAI Assistants API instead?

No. The Assistants API shut down on August 26, 2026. Use the Responses API plus the Conversations API for new builds and follow OpenAI's migration guide for older integrations. Responses supports hosted tools including file_search, web_search, MCP, and computer use.

You do not need a research team to build a useful research assistant. You need a measured pipeline that searches, verifies, cites, and preserves the context you are allowed to store. Build the smallest version that passes your evaluation set, then add memory and higher-cost models only where the evidence supports them.