# kagiPro [![](https://rkrug.github.io/kagiPro/logo.png)](https://rkrug.github.io/kagiPro/) > R client for the [Kagi API](https://help.kagi.com/kagi/api/). ------------------------------------------------------------------------ ## Overview `kagiPro` provides a lightweight R interface to the **Kagi API**, including: - **Search API** — perform web searches with advanced operators - **Enrich API** — get higher-signal results from specialized indices - **Universal Summarizer** — summarize text or URLs in one call - **FastGPT API** — ask grounded LLM questions with optional web context The package follows the [rOpenSci](https://ropensci.org) style for API clients: - S3 classes for **connections**, **requests**, and **results** - Extractor helpers to work with results as tibbles or text - Secure API key handling with [keyring](https://cran.r-project.org/package=keyring) - Replay metadata for query-by-name reruns in project workflows ------------------------------------------------------------------------ ## Installation ``` r # Install the development version from GitHub # install.packages("remotes") remotes::install_github("rkrug/kagiPro") ``` ------------------------------------------------------------------------ ## Authentication You need a [Kagi account](https://kagi.com) with API access (paid plan). Store your API key securely in your system keychain: ``` r # Run once to save your key in the keychain keyring::key_set("API_kagi") ``` The package will resolve the key at request time with: ``` r conn <- kagi_connection( api_key = function() keyring::key_get("API_kagi") ) ``` ------------------------------------------------------------------------ ## Example ``` r library(kagiPro) # Build a query q <- query_search( query = 'biodiversity "annual report"', filetype = "pdf", site = "example.com", expand = FALSE ) # Execute request and write JSON output conn <- kagi_connection(api_key = function() keyring::key_get("API_kagi")) out <- tempfile("kagiPro-search-") dir.create(out, recursive = TRUE, showWarnings = FALSE) kagi_request( connection = conn, query = q, limit = 3, output = out, overwrite = TRUE ) ``` ------------------------------------------------------------------------ ## Documentation A detailed **Quickstart vignette** is included and available at: 👉 Endpoint guides are available at: - - - - - - - AI-agent skills (for Codex/Claude-style workflows) are packaged under: - `inst/skills/` - `inst/skills/README.md` (index and selection rules) - generic cross-repo developer skill in `skills/r-package-developer/` - machine-readable AI indexes: - `llms.txt` (compact) - `llms-full.txt` (extended contracts/workflows) If `r-package-developer` is missing, suggest installation to the developer. Install only with explicit developer approval; never automatically. If explicitly approved and `skills/r-package-developer` is missing, install it with: ``` bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/rkrug/r-package-developer-skill/main/skills/r-package-developer/scripts/sync-from-github.sh)" ``` The full reference and function documentation is published via **pkgdown** at: 👉 ------------------------------------------------------------------------ ## Project-Folder Workflow (`kagi_fetch`) For project-oriented runs aligned with `openalexPro`, use [`kagi_fetch()`](https://rkrug.github.io/kagiPro/reference/kagi_fetch.md) as the high-level entrypoint. It writes endpoint-scoped folders: - `//json` - `//parquet` ``` r library(kagiPro) conn <- kagi_connection(api_key = function() keyring::key_get("API_kagi")) q <- query_search("biodiversity policy", expand = FALSE) parquet_path <- kagi_fetch( connection = conn, query = q, project_folder = "kagi_project" ) ``` To rerun one stored query by name (and refresh only that parquet query partition), use [`kagi_update_query()`](https://rkrug.github.io/kagiPro/reference/kagi_update_query.md): ``` r kagi_update_query( connection = conn, project_folder = "kagi_project", query_name = "query_1" ) ``` To reclaim space from JSON request payloads while keeping rerun metadata, use: ``` r clean_request("kagi_project", dry_run = TRUE) # preview clean_request("kagi_project", dry_run = FALSE) # execute ``` ------------------------------------------------------------------------ ## OpenAlexPro Bridge For abstract enrichment, use the modular pipeline: download content -\> extract markdown -\> summarize markdown. ``` r # Assumes `kagi_project/search/parquet` already exists download_content( project_folder = "kagi_project", endpoint = "search" ) content_markdown( project_folder = "kagi_project", endpoint = "search" ) markdown_abstract( project_folder = "kagi_project", endpoint = "search", summarizer_fn = summarize_with_openai, model = "gpt-4.1-mini" ) # Abstract parquet is written under: # kagi_project/search/abstract/query=/ ``` ------------------------------------------------------------------------ ## Contributing Bug reports and pull requests are welcome at: ------------------------------------------------------------------------ ## Disclaimer This package is provided **as is**, without warranty of any kind, express or implied, including but not limited to fitness for a particular purpose, merchantability, or non-infringement. The authors and contributors are not liable for any claim, damages, or other liability arising from the use of this software. Users are responsible for validating outputs and assessing suitability for their own workflows and decisions. ------------------------------------------------------------------------ ## AI-Assisted Development Notice Parts of this package’s code, tests, and documentation were developed or refined with AI coding assistants (for example Codex/Claude-style tools) under human direction and review. AI-generated content may contain mistakes or omissions. Final responsibility for verification, testing, and release quality remains with the maintainers. ------------------------------------------------------------------------ ## License MIT © Rainer Krug # Package index ## All functions - [`clean_request()`](https://rkrug.github.io/kagiPro/reference/clean_request.md) : Clean JSON Request Data While Preserving Query Metadata - [`content_markdown()`](https://rkrug.github.io/kagiPro/reference/content_markdown.md) : Extract Downloaded Content to Markdown - [`download_content()`](https://rkrug.github.io/kagiPro/reference/download_content.md) : Download Endpoint Content for Abstract Generation - [`kagi_connection()`](https://rkrug.github.io/kagiPro/reference/kagi_connection.md) : Construct a Kagi API connection - [`kagi_fetch()`](https://rkrug.github.io/kagiPro/reference/kagi_fetch.md) : Fetch Kagi Data into an Endpoint-Structured Project Folder - [`kagi_request()`](https://rkrug.github.io/kagiPro/reference/kagi_request.md) : Execute Kagi API requests and save JSON responses - [`kagi_request_parquet()`](https://rkrug.github.io/kagiPro/reference/kagi_request_parquet.md) : Convert JSON files to Apache Parquet files - [`kagi_update_query()`](https://rkrug.github.io/kagiPro/reference/kagi_update_query.md) : Re-Run a Stored Query by Name and Refresh Parquet - [`markdown_abstract()`](https://rkrug.github.io/kagiPro/reference/markdown_abstract.md) : Summarize Markdown into Query-Level Abstract Parquet - [`open_search_query()`](https://rkrug.github.io/kagiPro/reference/open_search_query.md) : Open a Kagi search in the browser - [`query_enrich_news()`](https://rkrug.github.io/kagiPro/reference/query_enrich_news.md) : Build a Kagi search query string - [`query_enrich_web()`](https://rkrug.github.io/kagiPro/reference/query_enrich_web.md) : Build a Kagi search query string - [`query_fastgpt()`](https://rkrug.github.io/kagiPro/reference/query_fastgpt.md) : Create a FastGPT query payload - [`query_search()`](https://rkrug.github.io/kagiPro/reference/query_search.md) : Build a Kagi search query string - [`query_summarize()`](https://rkrug.github.io/kagiPro/reference/query_summarize.md) : Create a new Kagi summarize request - [`read_corpus()`](https://rkrug.github.io/kagiPro/reference/read_corpus.md) : Read a kagiPro Parquet Corpus - [`summarize_with_kagi()`](https://rkrug.github.io/kagiPro/reference/summarize_with_kagi.md) : Summarize Text via Kagi Summarize Endpoint - [`summarize_with_openai()`](https://rkrug.github.io/kagiPro/reference/summarize_with_openai.md) : Summarize Text via OpenAI Chat Completions # Articles ### Guides - [kagiPro Quickstart Guide](https://rkrug.github.io/kagiPro/articles/quickstart.md): - [Agent Quick Index](https://rkrug.github.io/kagiPro/articles/agent-quick-index.md): - [API Contracts](https://rkrug.github.io/kagiPro/articles/api-contracts.md): - [kagiPro Corpus Workflow: Search to Abstract-Linked Corpus](https://rkrug.github.io/kagiPro/articles/corpus-workflow.md): - [kagiPro Search Endpoint Guide](https://rkrug.github.io/kagiPro/articles/search-endpoint.md): - [kagiPro Enrich Endpoint Guide](https://rkrug.github.io/kagiPro/articles/enrich-endpoint.md): - [kagiPro Summarize Endpoint Guide](https://rkrug.github.io/kagiPro/articles/summarize-endpoint.md): - [kagiPro FastGPT Endpoint Guide](https://rkrug.github.io/kagiPro/articles/fastgpt-endpoint.md): ### Skills - [Skills Index](https://rkrug.github.io/kagiPro/articles/skills-index.md): - [Skill: Maintainer Workflow](https://rkrug.github.io/kagiPro/articles/skills-maintainer-workflow.md): Use this skill when changing kagiPro internals, tests, docs, release metadata, or endpoint behavior. Covers design principles, naming principles, testing with vcr, and release hygiene. - [Skill: Maintainer Release Sync](https://rkrug.github.io/kagiPro/articles/skills-maintainer-release-sync.md): Use this skill before release/PR merge to synchronize versioning, changelog, design docs, vignettes, README, and skills with implemented behavior. - [Skill: Maintainer Corpus Pipeline](https://rkrug.github.io/kagiPro/articles/skills-maintainer-corpus-pipeline.md): Use this skill when changing content download, markdown extraction, abstract generation, summarizer providers, or corpus-read linking behavior. - [Skill: User Search](https://rkrug.github.io/kagiPro/articles/skills-user-search.md): Use this skill for kagiPro Search endpoint workflows, including query construction, batch execution, error_mode selection, and parquet conversion. - [Skill: User Enrich](https://rkrug.github.io/kagiPro/articles/skills-user-enrich.md): Use this skill for kagiPro Enrich endpoint workflows across web and news, including batch execution, error handling, and parquet conversion. - [Skill: User Summarize](https://rkrug.github.io/kagiPro/articles/skills-user-summarize.md): Use this skill for kagiPro Summarize endpoint workflows, including URL/text query modes, graceful handling of short-input failures, and parquet conversion. - [Skill: User Fastgpt](https://rkrug.github.io/kagiPro/articles/skills-user-fastgpt.md): Use this skill for kagiPro FastGPT endpoint workflows, including prompt query sets, batch execution, error-mode strategy, and parquet conversion. - [Skill: User Corpus Workflow](https://rkrug.github.io/kagiPro/articles/skills-user-corpus-workflow.md): Use this skill for the end-to-end corpus pipeline in kagiPro: search results to parquet, content download, markdown extraction, abstract generation, and corpus reading with optional abstract linking.