Loading...
Loading...
USE FOR AI-grounded answers via OpenAI-compatible /chat/completions. Two modes: single-search (fast) or deep research (enable_research=true, thorough multi-search). Streaming/blocking. Citations.
npx skill4agent add brave/brave-search-skills answersRequires API Key: Get one at https://api.search.brave.comPlan: Included in the Answers plan. See https://api-dashboard.search.brave.com/app/subscriptions/subscribe
| Use Case | Skill | Why |
|---|---|---|
| Quick factual answer (raw context) | | Single search, returns raw context for YOUR LLM |
| Fast AI answer with citations | | streaming, citations |
| Thorough multi-search deep research | | Iterative deep research, synthesized cited answer |
/res/v1/chat/completionsenable_citationsenable_research=truecurl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
"model": "brave",
"stream": false
}'curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "What are recent breakthroughs in fusion energy?"}],
"model": "brave",
"stream": true,
"enable_citations": true
}'curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "Compare quantum computing approaches"}],
"model": "brave",
"stream": true,
"enable_research": true,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}'POST https://api.search.brave.com/res/v1/chat/completionsX-Subscription-Token: <API_KEY>Authorization: Bearer <API_KEY>base_url="https://api.search.brave.com/res/v1"| Feature | Single-Search (default) | Research ( |
|---|---|---|
| Speed | Fast | Slow |
| Searches | 1 | Multiple (iterative) |
| Streaming | Optional ( | Required ( |
| Citations | | Built-in (in |
| Progress events | No | Yes ( |
| Blocking response | Yes ( | No |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| array | Yes | - | Single user message (exactly 1 message) |
| string | Yes | - | Use |
| bool | No | true | Enable SSE streaming |
| string | No | "US" | Search country (2-letter country code or |
| string | No | "en" | Response language |
| string | No | "moderate" | Search safety level ( |
| int | No | null | Upper bound on completion tokens |
| bool | No | false | Include inline citation tags (single-search streaming only) |
| object | No | null | OpenAI-compatible; |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| bool | No | | Enable research mode |
| bool | No | | Enable extended thinking |
| int | No | | Max tokens per query (1024-16384) |
| int | No | | Max total search queries (1-50) |
| int | No | | Max research iterations (1-5) |
| int | No | | Time budget in seconds (1-300) |
| int | No | | Results per search query (1-60) |
| Constraint | Error |
|---|---|
| "Blocking response doesn't support 'enable_research' option" |
| "Research mode doesn't support 'enable_citations' option" |
| "Blocking response doesn't support 'enable_citations' option" |
from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
response = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
stream=False,
)
print(response.choices[0].message.content)from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "What are the current trends in renewable energy?"}],
stream=True,
extra_body={"enable_citations": True}
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = await client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "Compare quantum computing approaches"}],
stream=True,
extra_body={
"enable_research": True,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)stream=false{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "The James Webb Space Telescope works by..."}, "index": 0, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 10, "completion_tokens": 50, "total_tokens": 60}
}data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Based on"},"index":0}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":" recent research"},"index":0}]}
data: [DONE]enable_citations=true| Tag | Purpose |
|---|---|
| Inline citation references |
| JSON cost/billing data |
| Tag | Purpose | Keep? |
|---|---|---|
| Generated search queries | Debug |
| URL counts (verbose) | Debug |
| URL selection reasoning | Debug |
| Stats: time, iterations, queries, URLs analyzed, tokens | Monitor |
| Knowledge gaps identified | Yes |
| Final synthesized answer (only the final answer is emitted; intermediate drafts are dropped) | Yes |
| JSON cost/billing data (included at end of streaming response) | Yes |
<usage><usage>{"X-Request-Requests":1,"X-Request-Queries":8,"X-Request-Tokens-In":15000,"X-Request-Tokens-Out":2000,"X-Request-Requests-Cost":0.005,"X-Request-Queries-Cost":0.032,"X-Request-Tokens-In-Cost":0.075,"X-Request-Tokens-Out-Cost":0.01,"X-Request-Total-Cost":0.122}</usage>base_url="https://api.search.brave.com/res/v1"enable_research=truebase_urlapi_keyenable_citations=truemessages<usage>