### Configuration File Example Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of a JSON configuration file for Brave Search CLI. Settings include API key, base URL, and timeout. ```json { "api_key": "BSA...", "base_url": "https://api.search.brave.com", "timeout": 30 } ``` -------------------------------- ### Install Brave Search CLI on Windows (PowerShell) Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use this PowerShell command to install the bx CLI on Windows systems. ```powershell powershell -ExecutionPolicy Bypass -c "irm https://raw.githubusercontent.com/brave/brave-search-cli/main/scripts/install.ps1 | iex" ``` -------------------------------- ### Load Custom Config File Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the `--config` flag to load a specific configuration file for different environments. ```bash bx --config ~/.config/brave-search/dev.json web "test" ``` -------------------------------- ### Install Brave Search CLI on macOS/Linux Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use this command to install the bx CLI on macOS and Linux systems via curl. ```bash curl -fsSL https://raw.githubusercontent.com/brave/brave-search-cli/main/scripts/install.sh | sh ``` -------------------------------- ### RAG Grounding with Token Budget Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the 'context' command for RAG/LLM grounding, specifying maximum tokens and a strict threshold. ```bash # RAG grounding with token budget bx context "Python TypeError cannot unpack non-iterable NoneType" --max-tokens 4096 --threshold strict ``` -------------------------------- ### Default Command Usage Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of running the CLI without specifying a subcommand, which defaults to the 'context' command. ```bash # Default subcommand is context bx "tokio spawn async task example" ``` -------------------------------- ### Web Search with Site Scoping and jq Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of performing a web search using the 'web' command, with site-specific scoping and piping results to 'jq' to extract URLs. ```bash # Web search with site: scoping bx web "site:docs.rs axum middleware" | jq '.web.results[].url' ``` -------------------------------- ### Image Search and Thumbnail Extraction Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the 'images' command for image search and extracting thumbnail sources using 'jq'. ```bash # Image search bx images "system architecture diagram microservices" | jq '.results[].thumbnail.src' ``` -------------------------------- ### AI Answer Streaming Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the 'answers' command to get AI-generated answers, with streaming enabled by default. ```bash # AI answer (streaming) bx answers "explain Rust lifetimes with examples" ``` -------------------------------- ### Autocomplete Suggestions with Count and jq Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the 'suggest' command for query autocomplete, specifying the number of suggestions and extracting queries with 'jq'. ```bash # Autocomplete bx suggest "how to implement" --count 10 | jq '.results[].query' ``` -------------------------------- ### Get Autocomplete/Query Suggestions Source: https://context7.com/brave/brave-search-cli/llms.txt Use `bx suggest` to get query suggestions for autocomplete. The `--rich` flag provides metadata, and `--lang` and `--country` can filter suggestions. ```bash bx suggest "how to implement" --count 10 | jq '.results[].query' ``` ```bash bx suggest "Rust error handling" --rich | jq . ``` ```bash bx suggest "machine learning" --lang en --country US --count 5 ``` -------------------------------- ### Agent Workflow: Debugging an Error Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using `bx context` to debug a specific Python error, with a token limit. ```bash # Agent encounters: "TypeError: cannot unpack non-iterable NoneType" bx "Python TypeError cannot unpack non-iterable NoneType" --max-tokens 4096 ``` -------------------------------- ### Location-Aware Web Search Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of performing a web search with location awareness using latitude, longitude, and city parameters. ```bash # Location-aware web search bx web "restaurants near me" --lat 37.7749 --long -122.4194 --city "San Francisco" ``` -------------------------------- ### AI Answer Non-Streaming with jq Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using the 'answers' command to get AI-generated answers without streaming, piping the output to 'jq' for JSON parsing. ```bash # AI answer (non-streaming) bx answers "compare SQLx and Diesel for Rust database access" --no-stream | jq . ``` -------------------------------- ### Local Proxy / Sandboxed Agents Setup Source: https://context7.com/brave/brave-search-cli/llms.txt Configure `bx` to point to a local reverse proxy for injecting API credentials outside the sandbox. Only loopback addresses are accepted. ```bash # Point bx at a local reverse proxy # bx --proxy http://127.0.0.1:8080 ... ``` -------------------------------- ### Focused Search with Goggles (Custom Re-ranking) Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of using Goggles to boost official docs, prefer specific paths, and suppress SEO spam for a search query. ```bash # Boost official docs, prefer /docs/ paths, suppress SEO spam bx "Python asyncio gather vs wait" \ --goggles '$boost=3,site=docs.python.org /docs/$boost=3 /blog/$downrank=2 $discard,site=geeksforgeeks.org $discard,site=w3schools.com' --max-tokens 4096 ``` -------------------------------- ### Local Places Search with jq Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of searching for local places using the 'places' command, specifying location and query, and extracting titles with 'jq'. ```bash # Local places bx places --location "San Francisco CA US" -q "coffee" | jq '.results[].title' ``` -------------------------------- ### Agent Workflow: Corrective RAG Loop Source: https://github.com/brave/brave-search-cli/blob/main/README.md Demonstrates a RAG loop: starting with a broad search, narrowing down, and then asking for a synthesized answer. ```bash # 1. Broad search bx "axum middleware authentication" --max-tokens 4096 ``` ```bash # 2. Too general? Narrow down bx "axum middleware tower layer authentication example" --threshold strict --max-tokens 4096 ``` ```bash # 3. Still need synthesis? Ask for an answer bx answers "how to implement JWT auth middleware in axum" --enable-research ``` -------------------------------- ### Research Mode for AI Answers Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of enabling research mode with the 'answers' command for more thorough AI-generated responses. ```bash # Research mode (multi-step, thorough) bx answers "what changed in React 19 vs React 18?" --enable-research ``` -------------------------------- ### Boost Official Sources for Python Errors with Goggles Source: https://github.com/brave/brave-search-cli/blob/main/README.md Apply Goggles rules to boost or discard specific domains for a given query. This example prioritizes official Python documentation and GitHub. ```bash bx "TypeError cannot unpack non-iterable NoneType" \ --goggles '$boost=3,site=docs.python.org $boost=2,site=github.com $discard,site=geeksforgeeks.org $discard,site=w3schools.com' ``` -------------------------------- ### Direct AI Answer with Streaming Source: https://github.com/brave/brave-search-cli/blob/main/README.md Get a direct AI-generated answer to a query. This command streams the response by default. ```bash bx answers "explain Rust lifetimes with examples" ``` -------------------------------- ### `bx web` Response Shape Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example JSON structure for the `bx web` command, including web, news, videos, and discussions results. ```json { "web": { "results": [{"title": "...", "url": "...", "description": "..."}] }, "news": { "results": [...] }, "videos": { "results": [...] }, "discussions": { "results": [...] } } ``` -------------------------------- ### News Search with Freshness Filter and jq Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of searching for news articles using the 'news' command, filtering by freshness (past day), and extracting titles with 'jq'. ```bash # News from the past day bx news "npm security advisory" --freshness pd | jq '.results[].title' ``` -------------------------------- ### `bx answers` Response Shape (Single Response) Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example JSON structure for a non-streamed response from the `bx answers` command. ```json {"choices": [{"message": {"content": "Rust lifetimes ensure references..."}}]} ``` -------------------------------- ### `bx context` Response Shape Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example JSON structure for the `bx context` command, showing grounding results with extracted content. ```json { "grounding": { "generic": [ { "url": "...", "title": "...", "snippets": ["extracted content...", "..."] } ] } } ``` -------------------------------- ### `bx answers` Response Shape (Streaming) Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example JSON structure for a single chunk of a streamed response from the `bx answers` command. ```json {"choices": [{"delta": {"content": "Rust lifetimes ensure references..."}}]} ``` -------------------------------- ### Web Search with Result Type Filtering Source: https://github.com/brave/brave-search-cli/blob/main/README.md Example of filtering web search results to include only specific types like 'web' and 'discussions'. ```bash # Filter result types bx web "rust" --result-filter "web,discussions" ``` -------------------------------- ### Error Handling Output Example Source: https://github.com/brave/brave-search-cli/blob/main/README.md Errors are printed to stderr with a human-readable summary, recovery hints, and the full JSON error body. Exit codes differentiate error types. ```text error: rate limited (429) — Request rate limit exceeded for plan. hint: retry after a short delay, or upgrade plan for higher rate limits {"type":"ErrorResponse","error":{"code":"RATE_LIMITED","status":429,...}} ``` -------------------------------- ### Override API Path with --endpoint Source: https://context7.com/brave/brave-search-cli/llms.txt Use the `--endpoint` flag to override the default API path, useful for accessing beta or internal endpoints. The path must start with `/` and contain only allowed characters. ```bash # Use a beta API version bx web "test" --endpoint /res/v2/web/search ``` ```bash # Combined with --extra for full control bx web "rust" \ --endpoint /res/v1/web/search \ --extra result_filter=web \ --extra count=5 ``` -------------------------------- ### Override Default API Path with --endpoint Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use the --endpoint flag to override the default API path, useful for internal or beta Brave endpoints. The path must start with '/'. ```bash bx web "test" --endpoint /res/v2/web/search ``` -------------------------------- ### Interpret Brave Search CLI Exit Codes Source: https://context7.com/brave/brave-search-cli/llms.txt Understand the meaning of different exit codes returned by Brave Search CLI commands for effective error handling in scripts. Includes a bash script example for checking exit codes. ```bash # Exit codes: # 0 = Success # 1 = Client error (bad request / 4xx general) # 2 = Usage error (bad CLI flags — clap) # 3 = Auth/permission error (401/403) # 4 = Rate limited (429) # 5 = Server/network error (5xx, timeout) # Check exit code in a script if bx context "query" --max-tokens 2048 > output.json; then echo "Success" jq '.grounding.generic[0].snippets[0]' output.json else code=$? case $code in 3) echo "Auth error — run: bx config show-key" ;; 4) echo "Rate limited — retrying in 5s..."; sleep 5 ;; 5) echo "Server error — check network" ;; *) echo "Error (code $code)" ;; esac fi ``` ```text # Sample stderr error output: # error: rate limited (429) — Request rate limit exceeded for plan. # hint: retry after a short delay, or upgrade plan for higher rate limits # {"type":"ErrorResponse","error":{"code":"RATE_LIMITED","status":429,...}} ``` -------------------------------- ### Pass Additional API Parameters with --extra Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use the --extra flag to pass additional API parameters not covered by named flags. Values are auto-typed for POST endpoints (numbers, booleans, strings) and always strings for GET endpoints. Be aware of potential key collisions with existing flags. ```bash bx web "rust" --extra custom_param=value ``` ```bash bx web "rust" --extra count=5 # overrides --count (with warning) ``` ```bash bx images "sunset" --extra safesearch=off ``` -------------------------------- ### Build Brave Search CLI from Source Source: https://context7.com/brave/brave-search-cli/llms.txt Instructions for building the Brave Search CLI from source using Cargo, including debug and release builds, and cross-compilation using Docker. Also covers running unit and end-to-end tests. ```bash # Prerequisites: Rust toolchain (see rust-toolchain.toml for pinned version) # Debug build cargo build # Optimized release build (~2 MB, fully stripped) cargo build --release ./target/release/bx --version # Static cross-compiled binaries via Docker make linux-amd64 # → dist/bx--linux-amd64 make linux-arm64 # → dist/bx--linux-arm64 make darwin-arm64 # → dist/bx--darwin-arm64 make windows-amd64 # → dist/bx--windows-amd64.exe make dist-all # → all platforms # Run unit tests (no API key required) make test-unit cargo test # Run end-to-end API smoke tests (requires BRAVE_SEARCH_API_KEY and jq) make test ``` -------------------------------- ### Build Static Binaries with Docker Source: https://github.com/brave/brave-search-cli/blob/main/README.md Produce fully static, cross-compiled binaries using Docker, GNU Make, and a POSIX shell. Requires Docker. On Windows, use Git Bash or WSL. The Makefile uses POSIX utilities. ```bash make linux-amd64 # → dist/bx--linux-amd64 make linux-arm64 # → dist/bx--linux-arm64 make darwin-arm64 # → dist/bx--darwin-arm64 make windows-amd64 # → dist/bx--windows-amd64.exe make windows-arm64 # → dist/bx--windows-arm64.exe make dist-all # → all of the above ``` -------------------------------- ### Configure API Key and Basic Usage Source: https://github.com/brave/brave-search-cli/blob/main/README.md Set your Brave Search API key and learn basic command usage, including shorthand for context queries and accessing help. ```bash bx config set-key YOUR_API_KEY # get a key at https://api-dashboard.search.brave.com ``` ```bash bx "your search query" # shorthand for: bx context "your search query" ``` ```bash bx --help # see all commands; bx --help for flags ``` ```bash # To search for a word matching a subcommand name: bx -- web or bx context "web" ``` -------------------------------- ### Set Up IPv6 Loopback Source: https://context7.com/brave/brave-search-cli/llms.txt Configure the Brave Search CLI to use a local IPv6 loopback address. This is for environments requiring IPv6 connectivity. ```bash BRAVE_SEARCH_BASE_URL=http://[::1]:8080 \ BRAVE_SEARCH_API_KEY=unused \ bx web "rust async" ``` -------------------------------- ### Agent Workflow: Evaluating a Dependency Source: https://github.com/brave/brave-search-cli/blob/main/README.md Check dependency maintenance and security issues using `bx context` and `bx news`. ```bash # Is this crate maintained? Any security issues? bx context "reqwest crate security issues maintained 2026" --threshold strict ``` ```bash bx news "reqwest Rust crate" --freshness pm ``` -------------------------------- ### Error Debugging with Domain Boosting Source: https://context7.com/brave/brave-search-cli/llms.txt Demonstrates using `bx context` with domain boosting (`--goggles`) to focus search results on specific sites for effective error debugging. Helps in finding solutions for complex issues. ```bash # Error debugging with domain boosting bx context "TypeError cannot unpack non-iterable NoneType Python" \ --goggles '$boost=3,site=docs.python.org $boost=2,site=stackoverflow.com $discard,site=geeksforgeeks.org' \ --max-tokens 4096 ``` -------------------------------- ### Version/Release Checking Beyond Training Cutoff Source: https://context7.com/brave/brave-search-cli/llms.txt Shows how to use `bx context` and `bx news` to retrieve information about the latest releases or changelogs for software, especially when the information is newer than the CLI's training data. ```bash # Version/release checking (beyond training cutoff) bx context "tokio 1.x latest release changelog" --max-tokens 2048 bx news "tokio rust async release" --freshness pm ``` -------------------------------- ### Local Proxy Configuration Source: https://github.com/brave/brave-search-cli/blob/main/README.md Demonstrates setting the `BRAVE_SEARCH_BASE_URL` environment variable to point the CLI to a local proxy. A placeholder API key is required when using a proxy. ```bash # Point bx at a local proxy on port 8080 with path prefix /brave BRAVE_SEARCH_BASE_URL=http://127.0.0.1:8080/brave bx "your query" # Or in config.json # { "base_url": "http://127.0.0.1:8080/brave" } ``` -------------------------------- ### Dependency Evaluation Pipeline with Brave Search CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Shows how to use `bx context` and `bx news` to evaluate dependencies, checking for security issues or recent changes. Useful for maintaining project health. ```bash # Dependency evaluation pipeline bx context "reqwest crate security issues maintained 2025" --threshold strict --max-tokens 2048 bx news "reqwest Rust crate" --freshness pm | jq '.results[].title' ``` -------------------------------- ### Focus on Rust Ecosystem Sources with Goggles Source: https://github.com/brave/brave-search-cli/blob/main/README.md Boost official Rust documentation and source repositories like docs.rs, crates.io, and GitHub for crate research. ```bash bx context "serde custom deserializer" \ --goggles '$boost=5,site=docs.rs $boost=5,site=crates.io $boost=3,site=github.com' --max-tokens 4096 ``` -------------------------------- ### Set Up IPv4 Loopback Proxy with Path Prefix Source: https://context7.com/brave/brave-search-cli/llms.txt Configure the Brave Search CLI to use a local IPv4 loopback proxy with a specific path prefix. This is useful for testing or custom integrations. ```bash BRAVE_SEARCH_BASE_URL=http://127.0.0.1:8080/brave \ BRAVE_SEARCH_API_KEY=unused \ bx context "axum middleware" --max-tokens 4096 ``` -------------------------------- ### Create and Use Goggles Rules from a File Source: https://github.com/brave/brave-search-cli/blob/main/README.md Define Goggles rules in a file and reference it using the '--goggles @file' syntax. This is ideal for agents to manage complex ranking preferences. ```bash cat > /tmp/rust.goggle << 'EOF' $boost=5,site=docs.rs $boost=5,site=crates.io $boost=3,site=github.com /blog/$downrank=3 $discard,site=w3schools.com $discard,site=geeksforgeeks.org EOF bx context "axum middleware tower" --goggles @/tmp/rust.goggle --max-tokens 4096 bx context "serde custom deserializer" --goggles @/tmp/rust.goggle --max-tokens 4096 ``` -------------------------------- ### Prioritize Docs Paths with Goggles Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use Goggles to boost specific URL path patterns, such as '/docs/', over others like '/blog/'. This helps in finding more relevant documentation. ```bash bx context "axum middleware tower" \ --goggles '/docs/$boost=5 /api/$boost=3 /blog/$downrank=3' --max-tokens 4096 ``` -------------------------------- ### Breaking Change Lookup with Brave Search CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Illustrates how to use `bx context` and `bx news` to find breaking changes in software versions before upgrading. Helps in planning migration strategies. ```bash # Breaking change lookup before upgrading bx context "Next.js 15 breaking changes migration guide" --max-tokens 8192 bx news "Next.js 15 release" --freshness pm ``` -------------------------------- ### Corrective RAG Loop with Brave Search CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Demonstrates using `bx context` for a corrective RAG loop, showing how to refine queries with `--threshold` and `--max-tokens` for better LLM input. Escalates to `bx answers` for synthesis tasks. ```bash # Corrective RAG loop bx context "axum middleware authentication" --max-tokens 4096 # Too general? Narrow down with --threshold strict bx context "axum middleware tower layer JWT authentication example" --threshold strict --max-tokens 4096 # Need synthesis? Escalate to answers bx answers "how to implement JWT auth middleware in axum" --enable-research ``` -------------------------------- ### Build Brave Search CLI with Cargo Source: https://github.com/brave/brave-search-cli/blob/main/README.md Build the Brave Search CLI from source using Cargo. Use 'cargo build' for a debug build and 'cargo build --release' for a smaller release build. ```bash # Debug build cargo build # Release build (~2 MB) cargo build --release ``` -------------------------------- ### Show Brave Search CLI Config File Path Source: https://context7.com/brave/brave-search-cli/llms.txt Prints the path to the Brave Search CLI configuration file. This helps in locating and manually editing the configuration. ```bash bx config path ``` -------------------------------- ### Agent Workflow: Checking for Breaking Changes Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use `bx context` and `bx news` to check for breaking changes before upgrading a dependency. ```bash bx context "Next.js 15 breaking changes migration guide" --max-tokens 8192 ``` ```bash bx news "Next.js 15 release" --freshness pm ``` -------------------------------- ### Show Full Brave Search CLI Configuration Source: https://context7.com/brave/brave-search-cli/llms.txt Displays the complete Brave Search CLI configuration, including API key (masked), base URL, and timeout settings. ```bash bx config show ``` -------------------------------- ### Using Faster Model in Brave CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Switches to a faster, potentially less thorough, model for quicker responses. ```bash bx answers "Hello" --model brave ``` -------------------------------- ### Basic RAG Grounding with bx context Source: https://context7.com/brave/brave-search-cli/llms.txt Performs basic RAG grounding using the `bx context` command. This is a shorthand for `bx context "query"`. ```bash bx "Python TypeError cannot unpack non-iterable NoneType" ``` -------------------------------- ### Use Hosted Goggles URL for Search Ranking Source: https://github.com/brave/brave-search-cli/blob/main/README.md Reference a Goggles configuration file hosted online (e.g., on GitHub) using its URL with the '--goggles' flag. This enables sharing and reusing ranking configurations. ```bash bx web "distributed systems" \ --goggles 'https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/tech_blogs.goggle' ``` -------------------------------- ### Citations and Entities in Brave CLI (Streaming) Source: https://context7.com/brave/brave-search-cli/llms.txt Enables streaming of results with citations and identified entities. Useful for real-time information retrieval. ```bash bx answers "who invented the internet?" --enable-citations --enable-entities ``` -------------------------------- ### Configure Brave Search API Key Directly Source: https://context7.com/brave/brave-search-cli/llms.txt Sets the Brave Search API key directly via a command-line argument. Replace 'BSA_YOUR_KEY_HERE' with your actual API key. ```bash bx config set-key BSA_YOUR_KEY_HERE ``` -------------------------------- ### Stdin Mode for Brave CLI Answers Source: https://context7.com/brave/brave-search-cli/llms.txt Processes a full OpenAI-compatible JSON body piped via stdin. Use '-' as the argument for answers. ```bash echo '{"messages":[{"role":"user","content":"review this code for security issues"}],"model":"brave-pro","stream":false}' \ | bx answers - ``` -------------------------------- ### RAG Grounding with Token Budget Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use the `context` command for RAG grounding, specifying a maximum token limit for the output. ```bash bx context "Python TypeError cannot unpack non-iterable NoneType" --max-tokens 4096 ``` -------------------------------- ### Configure Brave Search API Key Interactively Source: https://context7.com/brave/brave-search-cli/llms.txt Sets the Brave Search API key by prompting the user interactively. This method avoids storing the key in shell history. ```bash bx config set-key ``` -------------------------------- ### Include and Exclude Sites with Brave Search CLI Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use --include-site and --exclude-site flags to filter search results by domain. ```bash bx "rust axum" --include-site docs.rs --include-site github.com ``` ```bash bx web "rust tutorial" --exclude-site w3schools.com --exclude-site medium.com ``` -------------------------------- ### RAG Grounding with Token Budget Control Source: https://context7.com/brave/brave-search-cli/llms.txt Executes RAG grounding with specific controls for maximum tokens, tokens per URL, number of URLs, and a strictness threshold. ```bash bx context "axum middleware tower layer authentication" \ --max-tokens 4096 \ --max-tokens-per-url 1024 \ --max-urls 5 \ --threshold strict ``` -------------------------------- ### Extract Snippets with jq Source: https://context7.com/brave/brave-search-cli/llms.txt Demonstrates how to extract specific fields (URL and text snippets) from the RAG grounding output using `jq`. ```bash bx context "Rust ownership model" --max-tokens 2048 | \ jq '.grounding.generic[] | {url, text: .snippets[]}' ``` -------------------------------- ### Raw Web Search with Scoping Source: https://github.com/brave/brave-search-cli/blob/main/README.md Perform a raw web search, allowing for site scoping and result count specification. ```bash bx web "site:docs.rs axum middleware" --count 5 ``` -------------------------------- ### Video Search (Past Month) with jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for tutorial videos from the past month and extracts title, URL, and duration using jq. ```bash bx videos "Rust async await tutorial" \ --freshness pm \ --count 5 | \ jq '.results[] | {title, url, duration: .video.duration}' ``` -------------------------------- ### Run Brave Search CLI Tests Source: https://github.com/brave/brave-search-cli/blob/main/README.md Execute tests for the Brave Search CLI. Use 'make test' for end-to-end API smoke tests (requires API key) or 'make test-unit' for unit tests (no network required). ```bash # End-to-end API smoke suite (requires bash + jq + BRAVE_SEARCH_API_KEY/BRAVE_API_KEY) make test # Unit tests (no network/API key required) make test-unit ``` -------------------------------- ### Configure Brave Search API Key via Environment Variable Source: https://context7.com/brave/brave-search-cli/llms.txt Sets the Brave Search API key using the `BRAVE_SEARCH_API_KEY` environment variable. This is a common method for CI/CD or server environments. ```bash export BRAVE_SEARCH_API_KEY=BSA_YOUR_KEY_HERE ``` -------------------------------- ### Piping Request File to Brave CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Reads a JSON request from a file, pipes it to the Brave CLI for processing, and then uses jq to extract the content. ```bash cat request.json | bx answers - | jq '.choices[0].message.content' ``` -------------------------------- ### Local Place Search by Location String Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for local places (e.g., coffee shops) using a location string and extracts name and address using jq. ```bash bx places "coffee" --location "San Francisco CA US" | \ jq '.results[] | {name: .title, address: .postal_address}' ``` -------------------------------- ### Image Search with jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for images and extracts the title and thumbnail source URL using jq. ```bash bx images "microservices architecture diagram" --count 10 | \ jq '.results[] | {title, thumbnail: .thumbnail.src}' ``` -------------------------------- ### RAG Grounding with Goggles DSL for Re-ranking Source: https://context7.com/brave/brave-search-cli/llms.txt Applies advanced re-ranking to RAG grounding results using Brave's Goggles DSL. This allows fine-grained control over search result boosting and discarding. ```bash bx context "Python asyncio gather vs wait" \ --goggles '$boost=3,site=docs.python.org /docs/$boost=3 /blog/$downrank=2 $discard,site=geeksforgeeks.org $discard,site=w3schools.com' \ --max-tokens 4096 ``` -------------------------------- ### Custom Search Re-Ranking with Goggles Source: https://context7.com/brave/brave-search-cli/llms.txt Brave Goggles allow custom re-ranking rules (boost, downrank, discard) by domain or URL path. Rules can be inline, multiline via \n, from a file, or from stdin. Supported on `context`, `web`, and `news`. ```bash # Inline rules (single quotes required to prevent shell expansion of $) bx context "serde custom deserializer" \ --goggles '$boost=5,site=docs.rs $boost=5,site=crates.io $boost=3,site=github.com /blog/$downrank=3 $discard,site=w3schools.com' \ --max-tokens 4096 ``` ```bash # Multiline via \n escape in single-line form bx web "tokio runtime" \ --goggles '$boost=5,site=docs.rs\n$discard,site=medium.com' ``` ```bash # From a file (ideal for agents — generate once, reuse across queries) cat > /tmp/rust.goggle << 'EOF' $boost=5,site=docs.rs $boost=5,site=crates.io $boost=3,site=github.com /blog/$downrank=3 $discard,site=w3schools.com $discard,site=geeksforgeeks.org EOF bx context "axum middleware tower" --goggles @/tmp/rust.goggle --max-tokens 4096 bx context "serde custom deserializer" --goggles @/tmp/rust.goggle --max-tokens 4096 ``` ```bash # From stdin echo '$boost=5,site=docs.rs $boost=3,site=github.com' | bx web "tokio runtime" --goggles @- ``` ```bash # Hosted goggle URL (community-maintained) bx web "distributed systems" \ --goggles 'https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/tech_blogs.goggle' ``` ```bash # --include-site / --exclude-site (convenience shortcuts for common cases) bx context "axum middleware" \ --include-site docs.rs \ --include-site github.com \ --max-tokens 4096 ``` ```bash bx web "rust tutorial" --exclude-site w3schools.com --exclude-site medium.com ``` -------------------------------- ### Token Budget Control Source: https://github.com/brave/brave-search-cli/blob/main/README.md Control the token budget for a search query by setting maximum tokens, maximum tokens per URL, and maximum URLs. ```bash bx context "topic" --max-tokens 4096 --max-tokens-per-url 1024 --max-urls 5 ``` -------------------------------- ### Pipe Goggles Rules from Stdin Source: https://github.com/brave/brave-search-cli/blob/main/README.md Provide Goggles rules dynamically by piping them from another command using '--goggles @-'. This allows for flexible rule generation. ```bash echo '$boost=5,site=docs.rs $boost=3,site=github.com' | bx web "tokio runtime" --goggles @- ``` -------------------------------- ### Basic Web Search with jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Performs a basic web search and uses jq to extract the URLs from the web results. ```bash bx web "site:docs.rs axum middleware" | jq '.web.results[].url' ``` -------------------------------- ### Browse Places by Location Source: https://context7.com/brave/brave-search-cli/llms.txt Use the `bx places` command to browse locations without a specific query. Pipe output to `jq` for structured data extraction. ```bash bx places --location "NYC" --count 5 | jq '.results[].title' ``` ```bash bx places "museum" --location "Paris, France" --radius "2000" --count 10 ``` ```bash bx places "gas station" \ --location "London UK" \ --units metric \ --ui-lang en-GB | \ jq '.results[] | {name: .title, contact}' ``` -------------------------------- ### Pagination in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Retrieves results with specified count and offset for pagination. Useful for fetching data in chunks. ```bash bx web "rust async runtime" --count 10 --offset 20 ``` -------------------------------- ### RAG Grounding with Domain Allowlist Source: https://context7.com/brave/brave-search-cli/llms.txt Restricts RAG grounding results to specific domains using `--include-site`. Useful for focusing on trusted or relevant sources. ```bash bx context "reqwest crate usage examples" \ --include-site docs.rs \ --include-site github.com \ --max-tokens 4096 ``` -------------------------------- ### Image Search by Language and Region Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for images in a specific language and country, extracting URLs using jq. ```bash bx images "traditional Japanese architecture" \ --country JP \ --search-lang ja \ --count 15 | \ jq '.results[].url' ``` -------------------------------- ### Video Search with Operators Source: https://context7.com/brave/brave-search-cli/llms.txt Uses search operators to refine video searches, focusing on titles and retrieving up to 10 results. ```bash bx videos "intitle:\"Rust tutorial\" beginner" --operators --count 10 ``` -------------------------------- ### Local Place Search by Coordinates Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for local places (e.g., pizza restaurants) using geographic coordinates and limits results to 10. ```bash bx places "pizza" --latitude 37.7749 --longitude -122.4194 --count 10 ``` -------------------------------- ### Enabling Search Operators in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Activates the use of search operators like 'site:' and 'intitle:' for more precise web searches. ```bash bx web "site:github.com rust-lang/rust issue borrow checker" --operators ``` -------------------------------- ### Web Search with Extra Snippets Source: https://context7.com/brave/brave-search-cli/llms.txt Retrieves extra snippets along with web search results and extracts them using jq. ```bash bx web "axum routing" --extra-snippets | jq '.web.results[0].extra_snippets' ``` -------------------------------- ### Use Brave Answers Endpoint - Simple Mode Source: https://github.com/brave/brave-search-cli/blob/main/README.md Interact with the Brave Answers endpoint by passing a question directly. Supports streaming responses by default, single JSON responses with --no-stream, deep research with --enable-research, and faster models with --model. ```bash bx answers "explain Rust lifetimes with examples" # streaming (default) ``` ```bash bx answers "compare SQLx and Diesel" --no-stream # single JSON response ``` ```bash bx answers "what changed in React 19?" --enable-research # deep research ``` ```bash bx answers "Hello" --model brave # faster model ``` -------------------------------- ### Location-Aware RAG Grounding Source: https://context7.com/brave/brave-search-cli/llms.txt Performs RAG grounding with location-specific context by providing latitude, longitude, and city information. ```bash bx context "coffee shops open now" \ --lat 37.7749 --long -122.4194 \ --city "San Francisco" \ --max-tokens 2048 ``` -------------------------------- ### RAG Grounding with Domain Exclusions Source: https://context7.com/brave/brave-search-cli/llms.txt Excludes specific domains from RAG grounding results using `--exclude-site`. Helps to filter out noisy or irrelevant websites. ```bash bx context "Python asyncio tutorial" \ --exclude-site w3schools.com \ --exclude-site medium.com ``` -------------------------------- ### Pass Arbitrary API Parameters with --extra Source: https://context7.com/brave/brave-search-cli/llms.txt The `--extra` flag allows passing arbitrary API parameters not covered by named flags. Values are auto-typed for POST endpoints. It warns on collisions with existing flags. ```bash # Pass a custom parameter bx web "rust" --extra custom_param=value ``` ```bash # Override count (warns: "--extra 'count=5' overrides existing parameter") bx web "rust" --extra count=5 ``` ```bash # Multiple extras bx web "rust" --extra safesearch=off --extra count=10 ``` ```bash # Integer, float, and boolean auto-typing in POST bodies bx context "rust" --extra maximum_number_of_tokens=8192 # becomes JSON integer bx context "rust" --extra enable_local=true # becomes JSON boolean ``` ```bash # Images with extra parameter (GET endpoint — values are always strings) bx images "sunset" --extra safesearch=off ``` -------------------------------- ### Video Search with jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Performs a general video search and extracts the URLs of the results using jq. ```bash bx videos "distributed systems design" --count 10 | \ jq '.results[].url' ``` -------------------------------- ### Research Mode with Fine-Grained Controls Source: https://context7.com/brave/brave-search-cli/llms.txt Configures deep research mode with specific limits on the number of queries and time spent, and adjusts search context size. ```bash bx answers "explain Kubernetes networking" \ --enable-research \ --research-max-queries 5 \ --research-max-seconds 60 \ --search-context-size high ``` -------------------------------- ### Show Masked Brave Search API Key Source: https://context7.com/brave/brave-search-cli/llms.txt Displays the configured Brave Search API key, masked for security. Useful for verifying the key is set without revealing it. ```bash bx config show-key ``` -------------------------------- ### Use Brave Answers Endpoint - Stdin Mode Source: https://github.com/brave/brave-search-cli/blob/main/README.md Read a full JSON request body from stdin for the Answers endpoint by passing '-'. This allows for complex queries or piping data from other commands. ```bash echo '{"messages":[{"role":"user","content":"review this code for security issues"}],"model":"brave-pro"}' | bx answers - ``` ```bash cat request.json | bx answers - ``` -------------------------------- ### Downrank Blog Spam in News Results with Goggles Source: https://github.com/brave/brave-search-cli/blob/main/README.md Use Goggles to downrank specific domains, like medium.com, in news search results to reduce noise from less authoritative sources. ```bash bx news "npm security advisory" --freshness pd \ --goggles '$downrank=5,site=medium.com' ``` -------------------------------- ### Deep Research Mode in Brave CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Enables multi-step, thorough research for complex queries. May take longer to complete. ```bash bx answers "what changed in React 19 vs React 18?" --enable-research ``` -------------------------------- ### News Search with Goggles and jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Filters news by past day, applies Goggles to downrank specific sites, and extracts title, URL, and age using jq. ```bash bx news "npm security advisory" \ --freshness pd \ --goggles '$downrank=5,site=medium.com' | \ jq '.results[] | {title, url, age}' ``` -------------------------------- ### Date Range Freshness Filter in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Specifies a custom date range for freshness filtering in web searches. ```bash bx web "Rust 2024 edition" --freshness "2024-01-01to2024-12-31" ``` -------------------------------- ### Location-Aware Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Performs a web search that is aware of the user's location, specified by coordinates, city, and country. ```bash bx web "restaurants near me" \ --lat 37.7749 --long -122.4194 \ --city "San Francisco" \ --loc-country US ``` -------------------------------- ### Goggles for Web Search Ranking Control Source: https://context7.com/brave/brave-search-cli/llms.txt Uses Goggles to boost or discard specific sites, influencing search result ranking. Limits results to 5. ```bash bx web "Python request session" \ --goggles '$boost=5,site=docs.python-requests.org $boost=3,site=github.com $discard,site=geeksforgeeks.org' \ --count 5 ``` -------------------------------- ### Limiting Completion Tokens in Brave CLI Source: https://context7.com/brave/brave-search-cli/llms.txt Restricts the maximum number of tokens in the completion response to control output length. Disables streaming. ```bash bx answers "summarize the CAP theorem" --max-completion-tokens 256 --no-stream ``` -------------------------------- ### Image Search with Safe Search Source: https://context7.com/brave/brave-search-cli/llms.txt Performs an image search with a strict safe search filter, retrieving up to 20 results. ```bash bx images "chemistry lab equipment" --safesearch strict --count 20 ``` -------------------------------- ### Recent News Search (Past Month) Source: https://context7.com/brave/brave-search-cli/llms.txt Fetches recent news articles from the past month, limiting the results to 10. ```bash bx news "OpenAI API updates" --freshness pm --count 10 ``` -------------------------------- ### News Search (Past Week) with jq Extraction Source: https://context7.com/brave/brave-search-cli/llms.txt Searches for news articles from the past week and extracts their titles using jq. ```bash bx news "Rust language" --freshness pw | jq '.results[].title' ``` -------------------------------- ### Freshness Filter (Past Day) in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Filters web search results to include only those from the past day. Extracts URLs using jq. ```bash bx web "npm security advisory" --freshness pd | jq '.web.results[].url' ``` -------------------------------- ### Spell Check and Correct Queries Source: https://context7.com/brave/brave-search-cli/llms.txt Use `bx spellcheck` to correct misspelled queries. The corrected query can be captured in a variable for subsequent use. ```bash # Check and correct a misspelled query bx spellcheck "kubernetse dployment" | jq '.results[0].query' # → "kubernetes deployment" ``` ```bash # Use the corrected query in a pipeline CORRECTED=$(bx spellcheck "asnc programing rust" | jq -r '.results[0].query') bx context "$CORRECTED" --max-tokens 2048 ``` -------------------------------- ### Safe Search Control in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Applies a strict safe search filter to web results, limiting the number of results to 10. ```bash bx web "chemistry experiments" --safesearch strict --count 10 ``` -------------------------------- ### Filtering Result Types in Web Search Source: https://context7.com/brave/brave-search-cli/llms.txt Limits the search results to specific types, such as web pages and discussions. ```bash bx web "rust error handling" --result-filter "web,discussions" ``` -------------------------------- ### Non-Streaming AI Answer Source: https://context7.com/brave/brave-search-cli/llms.txt Obtains a single, non-streamed JSON response for an AI-grounded answer using the `--no-stream` flag. The output is piped to `jq .` for pretty-printing. ```bash bx answers "compare SQLx and Diesel for Rust database access" --no-stream | jq . ``` -------------------------------- ### Excluding Sites from News Search Source: https://context7.com/brave/brave-search-cli/llms.txt Performs a news search while excluding results from a specific domain, using past week freshness. ```bash bx news "kubernetes CVE" --exclude-site medium.com --freshness pw ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.