r9s
The official Python SDK and CLI for the r9s API.
Quick start
Requires Python 3.11+
Install:
pip install r9s
Or directly execute the CLI:
uvx r9s
Set your API key via .env file (recommended) or environment variable:
# Option 1: Create .env in your project directory
cat > .env << 'EOF'
R9S_API_KEY=your_api_key
R9S_BASE_URL=https://api.r9s.ai/v1
R9S_MODEL=gpt-5-mini
EOF
# Option 2: Export environment variables
export R9S_API_KEY="your_api_key"
The CLI automatically loads .env from the current directory (SDK usage does not auto-load). Disable with R9S_NO_DOTENV=1.
CLI usage
Chat (interactive, streaming by default):
r9s chat
Chat (stdin, useful for scripts/pipes):
echo "hello" | r9s chat
cat image.png | r9s chat
Resume a saved chat session (interactive selection):
r9s chat --resume
Agents (versioned, with audit trails, stored under ~/.r9s/agents/<name>/):
# Create an agent
r9s agent create reviewer \
--instructions "You are a code reviewer. Focus on bugs and security." \
--model gpt-5-mini
# Chat with the agent
r9s chat --agent reviewer
# Agents support variables
r9s agent create code-reviewer \
--instructions "Review {{language}} code for {{focus_areas}}" \
--model gpt-5-mini
r9s chat --agent code-reviewer --var language=Python --var focus_areas="security, performance"
# Pull an agent definition from git
r9s agent pull github:my-org/agent-definitions --path agents/reviewer
Commands (saved as TOML under ~/.r9s/commands/<name>.toml, prompt template only):
r9s command create summarize --prompt "Summarize: {{args}}"
In interactive chat, commands are available as slash commands:
/summarize hello world
Command templates:
{{args}}is replaced by the slash command arguments.!{...}runs a local shell command (bash -lc ...) after confirmation; pass-yto skip confirmation.
Run apps with r9s env injected (supported: claude-code, cc):
r9s run cc --model "$R9S_MODEL"
Configure local tools (supported: claude-code, cc, codex, qwen-code):
r9s set claude-code
r9s reset claude-code
Enable bash completion:
eval "$(r9s completion bash)"
List available models:
r9s models
r9s models --details # Show owner and creation date
Audio (TTS, transcription, translation):
# Text to speech
r9s audio speech "Hello world" -o hello.mp3
r9s audio speech "Welcome" -o welcome.wav -v nova
# Speech to text (transcription)
r9s audio transcribe recording.mp3
r9s audio transcribe meeting.wav -o transcript.txt -f text
# Translate audio to English
r9s audio translate chinese_audio.mp3 -o english.txt
See all options:
r9s -h
r9s chat -h
r9s agent -h
r9s command -h
r9s audio -h
r9s models -h
r9s run -h
Python SDK usage
Minimal example (reads R9S_API_KEY and optional R9S_BASE_URL from the environment):
from r9s.client import R9S
with R9S.from_env() as r9s:
res = r9s.chat.create(model="gpt-4o-mini", messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False)
Advanced SDK usage: docs/sdk-advanced.md
Development
Clone and install in editable mode with dev dependencies:
git clone https://github.com/r9s-ai/r9s-python.git
cd r9s-python
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev,test]"
Run tests:
pytest
Run linting/type checks:
ruff check src/
pyright
mypy src/
Metadata
Release files for r9s 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| r9s-0.9.0.tar.gz | 181.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| r9s-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 430.5 kB
Release files / r9s-0.9.0.tar.gz
| Download URL | r9s-0.9.0.tar.gz |
|---|---|
| Size | 181.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8ad38775617c0e9ce8d7cb80e957a76a2520423d3f891362a9c6fb72cc51372
|
|
BLAKE2b-256 checksum How to use checksums |
3af32e95197fe016a61323d9aa80cca74b181bd0dba3b3d7395954468c72cfdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / r9s-0.9.0-py3-none-any.whl
| Download URL | r9s-0.9.0-py3-none-any.whl |
|---|---|
| Size | 249.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b76ef7f0fa0e69a12bb8c0a487e1a6e0edfc9ae355e14a55f26b5fb9bf94a0a1
|
|
BLAKE2b-256 checksum How to use checksums |
2b280cedaf08fc35f48df0e4862633009b3b458c91fdab627c2412d6de62fbc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|