GET /v1/lucky
"I'm Feeling Lucky" - Get the single best matching page for a query. Returns the complete page with all its chunks, perfect for quick lookups and providing context to LLMs.
GET https://api.wikirest.com/v1/lucky Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
q | string | Required | Search query string |
format | string | Optional | chunks or concat (default: concat) |
Format Options
format=concat (default)
Returns a text field with all content concatenated into a single string.
Best for feeding to LLMs as a single context block.
format=chunks
Returns an array of chunk objects with section information. Best for granular access when you need section boundaries.
Response
{
"page": {
"page_id": "736",
"title": "Albert Einstein",
"url": "https://en.wikipedia.org/wiki/Albert_Einstein",
"rev_id": 1234567890,
"timestamp": "2024-01-15T10:30:00Z",
"source": {...},
"license": {...}
},
"chunks": {
"results": [...],
"offset": 0,
"limit": 10000,
"total": 45
},
"text": "Albert Einstein was a German-born theoretical physicist...",
"search_context": {
"query": "Albert Einstein",
"matched_chunk": {...},
"total_results": 1543,
"search_time_ms": 15
},
"attribution": {...},
"processingTimeMs": 15
} Response Fields
| Field | Type | Description |
|---|---|---|
page | object | Page metadata with attribution |
chunks | object | All chunks for this page |
text | string | Full concatenated text (with format=concat) |
search_context | object | Information about how the match was found |
Use Cases
- Quick lookups: Get the most relevant article for a topic
- LLM context: Provide full article content as context for AI models
- Direct answers: Answer "who is X" or "what is Y" questions
- Single-request retrieval: Get all content in one API call instead of search + fetch
Examples
Get full article as concatenated text
curl -H "X-API-Key: YOUR_KEY" \
"https://api.wikirest.com/v1/lucky?q=Albert+Einstein" Get article as individual chunks
curl -H "X-API-Key: YOUR_KEY" \
"https://api.wikirest.com/v1/lucky?q=machine+learning&format=chunks" Error Responses
| Status | Error | Description |
|---|---|---|
400 | missing q | Query parameter is required |
404 | no results found | No matching pages found |
401 | unauthorized | API key not provided |
429 | rate_limit_exceeded | Too many requests |
Related
- /v1/search - Search with multiple results
- /v1/page - Get page by ID