Skip to main content
Mintlify
current

Search documentation

Type to search this documentation.

Build implementation context

Searches Mintlify Index and returns source-cited content assembled within a token budget. Use this endpoint when an application or agent needs ready-to-use context in one request.

Related topics

POST /v1/context

cURL
curl --request POST \
  --url https://leaves.mintlify.com/api/universal-search/v1/context \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "query": "How should I configure caching in Next.js 16?",
  "product": "Next.js",
  "format": "txt",
  "tokenBudget": 3000
}'
Python
import requests

url = "https://leaves.mintlify.com/api/universal-search/v1/context"

payload = {
  "query": "How should I configure caching in Next.js 16?",
  "product": "Next.js",
  "format": "txt",
  "tokenBudget": 3000
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
JavaScript
const options = {method: "POST", headers: {"Authorization": "Bearer <token>", "Content-Type": "application/json"}, body: JSON.stringify({
  "query": "How should I configure caching in Next.js 16?",
  "product": "Next.js",
  "format": "txt",
  "tokenBudget": 3000
})};

fetch("https://leaves.mintlify.com/api/universal-search/v1/context", options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://leaves.mintlify.com/api/universal-search/v1/context",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"query\":\"How should I configure caching in Next.js 16?\",\"product\":\"Next.js\",\"format\":\"txt\",\"tokenBudget\":3000}",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://leaves.mintlify.com/api/universal-search/v1/context"

	payload := strings.NewReader("{\"query\":\"How should I configure caching in Next.js 16?\",\"product\":\"Next.js\",\"format\":\"txt\",\"tokenBudget\":3000}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
Java
HttpResponse<String> response = Unirest.post("https://leaves.mintlify.com/api/universal-search/v1/context")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\"query\":\"How should I configure caching in Next.js 16?\",\"product\":\"Next.js\",\"format\":\"txt\",\"tokenBudget\":3000}")
  .asString();
Ruby
require 'uri'
require 'net/http'

url = URI("https://leaves.mintlify.com/api/universal-search/v1/context")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\"query\":\"How should I configure caching in Next.js 16?\",\"product\":\"Next.js\",\"format\":\"txt\",\"tokenBudget\":3000}"

response = http.request(request)
puts response.read_body
200
{
  "requestId": "7f2ab8d1-3bea-4a29-bc51-c05a8d3a3e3c",
  "query": "How should I configure caching in Next.js 16?",
  "response": "### Caching and revalidating\nSource: https://nextjs.org/docs/app/getting-started/caching-and-revalidating\nUse the current caching APIs described in this guide.\n--------------------------------",
  "resultsCount": 3,
  "outputTokens": 1842
}
400
{
  "error": "Invalid request body"
}
401
{
  "error": "Unauthorized"
}
403
{
  "error": "IP address is not allowed for this API key"
}
429
{
  "error": "Rate limit exceeded. Please try again later"
}
500
{
  "error": "<string>"
}
Authorizationstringrequired

Mintlify Index API key with the mint_us_ prefix.

Typestring
querystringrequired

Implementation question to research.

Required string length: 1+

Typestring
product?string

Product or company name to use as an additional retrieval hint.

Required string length: 1+

Typestring
formatenum<string>required

Format of the response string. txt returns Markdown sections. json returns a serialized JSON object containing result items.

Available options: txt, json

Typeenum<string>
includeDomains?string[]

Domains to include in retrieval.

Typestring[]
excludeDomains?string[]

Domains to exclude from retrieval.

Typestring[]
tokenBudget?integer

Maximum number of output tokens.

Required range: 1 <= x <= 6000

Typeinteger
Default3000

200 — Context assembled successfully.

requestIdstringrequired

Unique identifier for the request.

Typestring
querystringrequired

Original query from the request.

Typestring
responsestringrequired

Assembled source content. The value is Markdown for txt requests and serialized JSON for json requests. The string can be empty when no content fits within the token budget.

Typestring
resultsCountintegerrequired

Number of source snippets included in the response.

Required range: 0 <= x

Typeinteger
outputTokensintegerrequired

Number of tokens in the assembled response.

Required range: 0 <= x

Typeinteger
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu