Prerequisites
- An available Kimi Code subscription is required, and set it as an environment variable:
KIMI_API_KEY - Python 3.9 or higher is required; depending on the environment, use
python3or thepythoncommand - Network access is required
Quick Start
- Set the API Key:
export KIMI_API_KEY=... - First use
kimi_search.pyto perform keyword search. - Then use
kimi_fetch.pyto fetch the main text by URL.
Script Description
scripts/kimi_search.py
Invoke POST /search。
python ./scripts/kimi_search.py \
--query "短剧创作指南" \
--limit 5 \
--timeout-seconds 30
Parameters:
--query-> Search keywords (required)--limit-> Number of results to return (1-20, default 5)--include-content-> Whether to enable page scraping (default false)--timeout-seconds-> Timeout (default 30 seconds)
scripts/kimi_fetch.py
Invoke POST /fetch。
python ./scripts/kimi_fetch.py \
--url "https://example.com" \
--timeout-seconds 30
Parameters:
--url-> Target URL (required)--timeout-seconds-> Timeout (default 30 seconds)
Escape Hatch
If there is no KIMI_API_KEYin the environment, it can be passed in via the --api-key parameter, but exposing sensitive information on the command line is strongly discouraged.
Agent Usage Conventions
- Enable
--include-contentand--limitas needed to control token costs.