---
title: "Wikipedia API: Search and Articles as JSON | Perceptlayer"
description: "Search Wikipedia and fetch an article as JSON with two 1-credit endpoints: read title, url, snippet and updated_at to ground an AI agent's answers."
url: https://perceptlayer.com/blog/wikipedia-api-json
---

[Blog](https://perceptlayer.com/blog) / [API guides](https://perceptlayer.com/blog/category/api-guides)

# Wikipedia API: Search and Articles as JSON

19 Nov 2026 Perceptlayer 7 min read

Perceptlayer's Wikipedia API gives you two JSON endpoints: `GET /v1/wikipedia/search` finds articles for a query, and `GET /v1/wikipedia/article` fetches one article by `title`. Each successful call costs 1 credit, so finding an article and fetching it costs 2. Search results carry the fields an AI agent or RAG pipeline needs to pick and cite a source: `title`, `url`, `snippet`, `word_count` and `updated_at`. This guide shows both requests, the parameters, a recorded response and the cost.

## Key takeaways

-   `GET /v1/wikipedia/search` takes a required `q` (up to 300 characters) and optional `language`, `page` and `per_page`; `GET /v1/wikipedia/article` takes a required `title` (up to 255 characters) and optional `language`.
-   Both endpoints cost 1 credit per successful call; a failed call costs nothing and returns `X-Credits-Used: 0`.
-   Each search result carries `title`, `page_id`, `url`, `size_bytes`, `word_count`, `snippet`, `snippet_html` and `updated_at`.
-   `language` accepts 12 values: `en`, `de`, `fr`, `es`, `it`, `pt`, `nl`, `ja`, `ru`, `pl`, `sv` and `zh`.
-   One search plus one article fetch is 2 credits, so the 100 signup credits cover 50 grounded lookups.

## Why ground an agent in a Wikipedia article?

An agent that answers from its training data alone can't tell you where a fact came from or how current it is. Grounding fixes that: before the model answers, your code finds a source, puts its text in the prompt and keeps the link so the answer can cite it. Wikipedia suits this for general-knowledge questions about people, places, events and concepts, because each article has a stable title and URL you can show the user.

The Wikipedia API on Perceptlayer splits the job into two steps. The `search` endpoint turns the user's question into a ranked list of candidate articles, each with a short `snippet` and an `updated_at` timestamp. The `article` endpoint then fetches the one you choose by its `title`. Your pipeline decides which result to fetch, how much text to pass to the model and how to show the citation.

Wikipedia also publishes its own APIs, with their own limits and terms. Compare them with this one for your workload and pick the one that fits. Whichever you use, Wikipedia content carries its own licence, and you must follow it when you reuse or show article text.

## How do you search Wikipedia for an article?

Send a `GET` request to `https://api.perceptlayer.com/v1/wikipedia/search` with your query in `q` and your key in the `X-API-Key` header. Add `language` to search one language edition. This is the request behind the recorded response used in this guide:

```bash
curl "https://api.perceptlayer.com/v1/wikipedia/search?q=Albert+Einstein&language=en" \
  -H "X-API-Key: $API_KEY"
```

Keys start with `sk_live_`. Where you can't set a header, put the key in the `api_key` query parameter instead; the [authentication docs](https://docs.perceptlayer.com/authentication) cover both. Every successful response carries `X-Credits-Used` and `X-Credits-Remaining` headers, so a pipeline can log what each lookup cost and the balance left.

To fetch the article itself, call the `article` endpoint with the title you picked:

```bash
curl "https://api.perceptlayer.com/v1/wikipedia/article?title=Albert+Einstein&language=en" \
  -H "X-API-Key: $API_KEY"
```

The search result's field is called `title` and the article endpoint's required parameter is called `title`; the names match. We don't have a recorded `article` response to show here, so run that call in the playground on the [Article endpoint page](https://perceptlayer.com/apis/wikipedia/article) and look at the fields before you map them into your pipeline.

## Which parameters do the two endpoints take?

The two endpoints take five parameters between them. `search` needs only `q`; `article` needs only `title`. Both accept the same `language` values, so a pipeline that searches the German edition can fetch from it too. The table lists every parameter with the constraints the API documents. Nothing else about them is documented, so don't rely on a default page size; set `per_page` when your code depends on how many results come back.

| Endpoint | Parameter | Type | Required | Documented constraint |
| --- | --- | --- | --- | --- |
| `search` | `q` | string | yes | Up to 300 characters |
| `search` | `language` | string | no | One of `en`, `de`, `fr`, `es`, `it`, `pt`, `nl`, `ja`, `ru`, `pl`, `sv`, `zh` |
| `search` | `page` | integer | no | No further constraint documented |
| `search` | `per_page` | integer | no | No further constraint documented |
| `article` | `title` | string | yes | Up to 255 characters |
| `article` | `language` | string | no | One of `en`, `de`, `fr`, `es`, `it`, `pt`, `nl`, `ja`, `ru`, `pl`, `sv`, `zh` |

The [Search endpoint page](https://perceptlayer.com/apis/wikipedia/search) and the [Article endpoint page](https://perceptlayer.com/apis/wikipedia/article) list the same parameters, each with a playground where you can run a real call with your key.

## What does the search response contain?

The search response is one JSON object with `success`, a `data` block and a `meta` block. `data` repeats your search parameters, reports the total number of hits and the paging state, and holds the `results` array. `meta` carries the `request_id` and the credits the call used. This is the recorded response for `q=Albert Einstein` in English, trimmed:

```json
{
  "success": true,
  "data": {
    "search_parameters": {
      "q": "Albert Einstein",
      "language": "en"
    },
    "total_hits": 7560,
    "page": 1,
    "per_page": 20,
    "has_more": true,
    "results": [
      {
        "title": "Albert Einstein",
        "page_id": 736,
        "url": "https://en.wikipedia.org/wiki/Albert_Einstein",
        "size_bytes": 240550,
        "word_count": 24016,
        "snippet": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist best known for developing the theory of relativity. Einstein also",
        …
        "updated_at": "2026-11-09T12:38:29Z"
      },
      {
        "title": "Hans Albert Einstein",
        "page_id": 1373258,
        "url": "https://en.wikipedia.org/wiki/Hans_Albert_Einstein",
        …
        "word_count": 1222,
        …
        "updated_at": "2026-09-01T00:57:53Z"
      }
    ]
  },
  "meta": {
    "endpoint_family": "search",
    "request_id": "req_84b4048f2c8d48f2b88a39e61725f737",
    "credits_charged": 1,
    …
  }
}
```

### Which fields does a RAG pipeline use?

Most of a grounding step runs on five fields per result. The table says what each one does in a pipeline.

| Field | What a pipeline does with it |
| --- | --- |
| `title` | Shown to the model and the user; passed as `title` to the `article` endpoint |
| `url` | The citation link in the final answer |
| `snippet` | Plain-text preview for ranking or a quick answer; `snippet_html` holds the same text with match highlighting |
| `word_count`, `size_bytes` | Tell you how large the article is before you fetch it, so you can budget prompt space |
| `updated_at` | Stored with the citation, so the answer says how recent its source was |
| `page_id` | A numeric ID to deduplicate results across queries |

The paging fields sit beside `results`: `total_hits` (7,560 here), `page`, `per_page` and `has_more`. When `has_more` is true and the first page held nothing useful, ask for the next `page`. Each page is another call and another credit.

### Why check word\_count before fetching?

The two recorded results differ in size by a factor of about 20: 24,016 words for "Albert Einstein" against 1,222 for "Hans Albert Einstein". A full article of 24,000 words is more than most prompts should carry. Reading `word_count` first lets you decide to fetch the article and split it into chunks, or to answer from the `snippet` alone.

## How do you turn search results into grounding context?

The script below searches Wikipedia for the user's question, keeps the top results and builds a context block with a numbered citation for each one. It reads only fields shown in the recorded response, and it waits on a 429 or 503 using the `Retry-After` header. Pass the `context` string to your model with an instruction to answer only from it and to cite the numbers.

```python
import os
import time

import requests

API_KEY = os.environ["API_KEY"]
BASE = "https://api.perceptlayer.com/v1/wikipedia"

def get(path, params, attempts=3):
    for _ in range(attempts):
        r = requests.get(f"{BASE}/{path}", params=params,
                         headers={"X-API-Key": API_KEY}, timeout=60)
        if r.status_code in (429, 503):
            time.sleep(int(r.headers.get("Retry-After", "5")))
            continue
        r.raise_for_status()
        return r.json()
    raise RuntimeError(f"gave up on {path} {params}")

def ground(question, language="en", keep=3):
    body = get("search", {"q": question, "language": language})
    results = body["data"]["results"][:keep]
    blocks, sources = [], []
    for n, item in enumerate(results, start=1):
        blocks.append(f"[{n}] {item['title']} ({item['word_count']} words)\n{item['snippet']}")
        sources.append(f"[{n}] {item['url']} (updated {item['updated_at']})")
    print("credits used:", body["meta"]["credits_charged"])
    return "\n\n".join(blocks), "\n".join(sources)

context, sources = ground("Albert Einstein")
print(context)
print(sources)
```

For short factual questions, the snippets may be enough. For longer answers, take the top result's `title`, call the `article` endpoint with it, and chunk the text you get back; check that response in the playground first, since this guide doesn't record its fields. Keep the citation list either way: it is what lets a user check the answer against the source.

### Can an agent call these endpoints itself?

Yes. Through the MCP server at `https://api.perceptlayer.com/mcp`, an agent finds the Wikipedia endpoints with `search_endpoints`, reads their parameters with `get_endpoint` (both cost nothing) and runs them with `call_endpoint`, which spends credits only on success and reports the credits used and remaining. The [AI agents docs](https://docs.perceptlayer.com/ai-agents) show the setup, including the Claude Code command.

## What does each grounded answer cost?

Each successful call costs 1 credit, whichever endpoint you call. A lookup that answers from snippets is 1 credit; one that searches and then fetches the top article is 2. Extra result pages and extra article fetches add 1 credit each. Failed calls are free, so a 503 followed by a successful retry still costs 1 credit.

| Workload | Arithmetic | Credits |
| --- | --- | --- |
| Snippet-only answers, 100 questions | 100 × 1 search × 1 credit | 100 |
| Search plus top article, 50 questions | 50 × (1 + 1) × 1 credit | 100 |
| Search plus top 3 articles, 1,000 questions | 1,000 × (1 + 3) × 1 credit | 4,000 |
| Search plus top article, 20,000 questions | 20,000 × 2 × 1 credit | 40,000 |

The 100 free credits on signup, granted once after you verify your email, cover the first two rows. The third fits the Starter pack's 10,000 credits, and the fourth fits the Build pack's 50,000. Purchased credits last 12 months, with no subscription. See [pricing](https://perceptlayer.com/pricing) for what credits cost and the [credits docs](https://docs.perceptlayer.com/credits) for how debits work.

The [API guides](https://perceptlayer.com/blog/category/api-guides) cover the same search-then-fetch pattern for other sources. To start, run the `search` endpoint in the playground on the [Wikipedia API page](https://perceptlayer.com/apis/wikipedia) with a question your agent gets, then [get a free API key](https://perceptlayer.com/signup) and drop the script into your pipeline.

## APIs in this post

-   [Wikipedia **1 credit per call** · 2 endpoints](https://perceptlayer.com/apis/wikipedia)

## Frequently asked questions

### How much does the Wikipedia API cost per article?

Each successful call to `/v1/wikipedia/search` or `/v1/wikipedia/article` costs 1 credit. Finding an article with search and then fetching it is 2 credits. Failed calls cost nothing and return `X-Credits-Used: 0`. The 100 free credits you get once on signup cover 50 search-and-fetch lookups; the pricing page lists what credit packs cost.

### Which languages can I search?

Both endpoints take an optional `language` parameter with one of 12 values: `en`, `de`, `fr`, `es`, `it`, `pt`, `nl`, `ja`, `ru`, `pl`, `sv` or `zh`. The recorded search used `en`, and its result URLs point at the English edition. Use the same `language` for the search and the article fetch, so the title you pass matches the edition you searched.

### Can I reuse Wikipedia text in my product?

Wikipedia content carries its own licence, and you must follow it when you reuse, quote or show article text, including text an agent repeats in its answers. Read the licence before you ship. Keeping the `url` from each search result with every answer makes attribution straightforward, because the pipeline already knows which article each passage came from.

### What happens if a search finds nothing useful?

Check `total_hits` and `has_more` in the response. When the first page held nothing relevant and `has_more` is true, request the next `page`, at 1 credit per page. If the query is too vague, rewrite it before searching again. Errors come back with an HTTP status and a JSON body with `code`, `message` and `request_id`; the errors docs list every code.

### How fast can I send requests?

Rates are per account, shared by all its keys, and counted per minute. Free accounts get 1 request a second, 60 a minute; paying accounts run at least 5 a second, depending on the pack. Every response carries `RateLimit-Remaining` and `RateLimit-Reset`, and a 429 carries `Retry-After` with the seconds to wait. The rate limits docs have the details.

wikipedia rag ai agents search api python

## More from the blog

1.  [API guides](https://perceptlayer.com/blog/category/api-guides) 15 Aug 2026 Updated 10 Nov 2026 Perceptlayer 7 min read
    
    ## [Brave Search API: Official Plans or One Multi-Source Key](https://perceptlayer.com/blog/brave-search-api-results-json)
    
    Brave's official Search API has freshness, country and Goggles filters. When it fits, and when one key for Brave, Google and Bing at 1 credit a query wins.
    
2.  [API guides](https://perceptlayer.com/blog/category/api-guides) 26 Nov 2026 Perceptlayer 7 min read
    
    ## [Depop API: Resale Listings as JSON](https://perceptlayer.com/blog/depop-api-json)
    
    Search Depop listings as JSON with brand, condition, sizes and price.amount per item; the recorded jacket search had a total\_count of 6,815,522. 1 credit.
    
3.  [API guides](https://perceptlayer.com/blog/category/api-guides) 26 Nov 2026 Perceptlayer 7 min read
    
    ## [Similarweb API: Website Traffic Data as JSON](https://perceptlayer.com/blog/similarweb-api-json)
    
    Get Similarweb traffic estimates as JSON: visits, bounce\_rate, traffic\_sources, top\_countries and top\_keywords for a domain, at 1 credit a call.
