Overview
The Context API returns the content of web pages you already have URLs for. Send a batch of URLs in one request and get one result per URL, in request order. Each result can include the page as Markdown, its HTML, its links, the passages most relevant to a query, and page metadata such as title, language, and publication date. You choose how old a stored copy can be, or force a live fetch. You can also add up to five yes or no criteria that a decision model scores on each page.
Each
ok or not_modified result is billed per URL, failed URLs are free, and criteria scoring is billed as Decisions API input tokens on top. See Context API pricing.
To find pages for a query, use the Search API. For a generated answer with citations, use the Agent API. You can also try the Context API in the Playground.
Authentication
Create an API key in the API Console and set it as an environment variable. Both libraries read it automatically:- macOS/Linux
- Windows
- macOS/Linux
- Windows
Installation
Install a version that includes the Context API:Fetch a Page
Send the URLs toPOST /v1/context. Without formats, each result has the page as Markdown plus its metadata:
Response
Response
metadata.origin is cached because the API returned a stored copy of the page, fetched at metadata.fetched_at. usage.fetched_urls is the number of billed URLs, and usage.cost.total_cost is their cost in USD at list price, before any account-specific discounts, credits, or adjustments.
Check Each Result
The request returns HTTP200 even when some URLs fail, so check status.type on each result before you use its content. Only ok results have content. Formats & Freshness lists every status type and what to do with it.
Rate Limits
Your usage tier sets the requests per second and the most URLs one request can carry. See Context API rate limits.Next Steps
Formats & Freshness covers the other output formats, page metadata, stored copies, conditional requests, and error handling. Score Pages with Criteria adds yes or no questions to a request. Time Machine covers thesnapshot_as_of parameter.
Formats & Freshness
Highlights, HTML, links, metadata, stored copies, and per-URL errors
Score Pages with Criteria
Score each fetched page with yes or no questions and filter on the scores
API Reference
Request and response schemas for POST /v1/context
Reading List Q&A Cookbook
Fetch highlights for a question and answer it with numbered citations
Prompt Injection Cookbook
Screen fetched pages for prompt injection before your model reads them