Getting Started
Get up and running with WikiRest API in under 5 minutes.
Step 1: Get your API key
Create a free account to get your API key. No credit card required. The free tier includes 5,000 requests per month.
Step 2: Make your first request
Try searching Wikipedia with a simple cURL command:
curl -H "X-API-Key: YOUR_API_KEY" \
"https://api.wikirest.com/v1/search?q=machine+learning&limit=3" Step 3: Explore the response
You'll receive a JSON response with search results:
{
"hits": [
{
"id": "12345_1",
"page_id": 12345,
"rev_id": 1234567890,
"title": "Machine learning",
"section": "Overview",
"text": "Machine learning is a subset of artificial intelligence...",
"chunk_id": 1,
"url": "https://en.wikipedia.org/wiki/Machine_learning",
"source": {
"project": "en.wikipedia.org",
"source_url": "https://en.wikipedia.org/wiki/Machine_learning",
"permalink": "https://en.wikipedia.org/w/index.php?curid=12345&oldid=1234567890"
},
"license": {
"name": "CC BY-SA 4.0",
"url": "https://creativecommons.org/licenses/by-sa/4.0/"
},
"_formatted": {
"text": "Machine learning is a subset of artificial intelligence..."
}
}
],
"query": "machine learning",
"processingTimeMs": 12,
"estimatedTotalHits": 1543,
"attribution": {
"license": { "name": "CC BY-SA 4.0", "url": "..." },
"attribution_notice": "Content derived from Wikipedia..."
}
} Understanding the response
| Field | Description |
|---|---|
hits | Array of matching text chunks |
id | Unique chunk identifier (page_id + chunk_id) |
page_id | Wikipedia page ID |
title | Article title |
section | Section heading (if any) |
text | Plain text content (~500 tokens) |
url | Link to Wikipedia article |
source | Wikipedia source URLs for attribution |
license | CC BY-SA 4.0 license information |
_formatted | Highlighted text with <em> tags |
attribution | Top-level attribution notice (required for compliance) |
Common use cases
RAG (Retrieval-Augmented Generation)
Use WikiRest to ground your LLM responses with factual Wikipedia content. The pre-chunked passages are optimized for context windows.
# Python example with OpenAI
import requests
import openai
# Search Wikipedia
wiki_response = requests.get(
"https://api.wikirest.com/v1/search",
headers={"X-API-Key": "YOUR_API_KEY"},
params={"q": "quantum computing", "limit": 3}
).json()
# Build context from chunks
context = "\n\n".join([
f"Source: {hit['title']}\n{hit['text']}"
for hit in wiki_response["hits"]
])
# Use with OpenAI
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": f"Use this context:\n{context}"},
{"role": "user", "content": "Explain quantum computing"}
]
) Building a search interface
Create an instant Wikipedia search for your application:
// JavaScript
const searchWikipedia = async (query) => {
const response = await fetch(
`https://api.wikirest.com/v1/search?q=${encodeURIComponent(query)}&limit=10`,
{ headers: { "X-API-Key": "YOUR_API_KEY" } }
);
return response.json();
};
// Display results with highlighting
const results = await searchWikipedia("artificial intelligence");
results.hits.forEach(hit => {
console.log(`${hit.title}: ${hit._formatted.text}`);
}); Next steps
- Authentication guide - Learn about API key management
- API Reference - Explore all endpoints
- Rate limiting - Understand usage limits
- Examples - Code samples in multiple languages