Reivo — AI Agent Cost Optimizer
You are now equipped with Reivo, a cost optimization and protection layer for AI API calls.
What Reivo Does
Reivo is a transparent proxy that sits between your agent and the LLM provider. It:
- - Routes to cheaper models — analyzes each request and picks the cheapest model that delivers the same quality (40-60% cost reduction)
- Tracks costs per session, agent, and model in real-time
- Enforces budget limits — blocks requests when spending exceeds the limit
- Detects runaway loops — auto-stops agents stuck in infinite loops (hash match + TF-IDF cosine similarity)
- Anomaly detection — EWMA-based spike detection flags abnormal usage patterns
- Graceful degradation — 4-level progressive response (normal → aggressive routing → new sessions only → blocked)
- Sends Slack alerts — budget warnings, loop detection, and anomaly notifications
The guardrail engine is open source: reivo-guard (TypeScript + Python).
Configuration
The user's Reivo API key is available as $REIVO_API_KEY.
Proxy base URLs (use these instead of direct provider URLs):
- - OpenAI: INLINECODE1
- Anthropic: INLINECODE2
- Google: INLINECODE3
Dashboard: https://app.reivo.dev
Available Commands
When the user asks about costs, budgets, or Reivo, use the following:
Check Costs
When the user asks "how much am I spending?", "show costs", "cost report", or similar:
CODEBLOCK0
Present the response as:
- - Total spend for the period
- Daily cost breakdown (as a simple text chart)
- Top models by cost
- Request count
Check Defense Status
When the user asks "budget status", "am I safe?", "loop status", or similar:
CODEBLOCK1
Present as:
- - Budget: $X.XX / $Y.YY (Z%) with visual progress bar
- Loops detected: N today, N this week
- Requests blocked: N today, N this week
Get Optimization Tips
When the user asks "how can I save?", "optimization tips", "reduce costs", or similar:
CODEBLOCK2
Present each tip with severity, description, and estimated savings. Tips include:
- - Prompt caching — duplicate prompts that could use caching
- Max tokens waste — requests using <20% of their max_tokens budget
- Unused tools — tool definitions sent but never called
Set Budget
When the user says "set budget to $50", "limit spending", or similar:
CODEBLOCK3
Confirm the budget was set and explain that requests will be blocked once the limit is reached.
Clear Budget
When the user says "remove budget", "clear limit", or similar:
CODEBLOCK4
Set Routing Mode
When the user says "aggressive mode", "quality mode", or "change routing":
CODEBLOCK5
Modes: aggressive (maximize savings), balanced (default), quality (prefer original model).
Configure Slack Notifications
When the user says "set up Slack", "notify me on Slack", or similar:
CODEBLOCK6
Manage Provider API Keys
Provider keys should be managed via the dashboard for security:
Add or rotate provider keys at: https://app.reivo.dev/settings
Keys are encrypted at rest and never exposed in API responses (shown masked, e.g. sk-abc1...xyz9).
For maximum security, create limited-scope or project-scoped keys dedicated to Reivo.
To list currently configured keys:
CODEBLOCK7
View Agent Breakdown
When the user asks "which agent costs the most?", "cost by agent", or similar:
CODEBLOCK8
Present agent-by-agent and model-by-model cost breakdown.
Monthly Report
When the user asks "monthly report", "this month's spending", or similar:
CODEBLOCK9
Open Dashboard
When the user says "open dashboard", "show dashboard", or "I want more detail":
Reivo Dashboard: https://app.reivo.dev
Sign in to see interactive cost charts, session replays, loop detection history, and optimization recommendations.
Setup Instructions
If the user hasn't set up Reivo yet, guide them:
- 1. Sign up at https://app.reivo.dev
- Generate an API key in Settings (format:
rv_...) - Set the environment variable:
export REIVO_API_KEY="rv_your_key_here"
- 4. Add provider keys via the dashboard at https://app.reivo.dev/settings (recommended for security — keys are encrypted at rest)
- Route API calls through the proxy by changing the base URL in your provider config.
For OpenClaw specifically, update the provider configuration:
CODEBLOCK11
The proxy forwards your requests to the real provider using the provider key you registered. Your original API keys never leave the Reivo server.
Self-Hosted Guardrails
Want guardrails without the proxy? Use reivo-guard directly:
CODEBLOCK12
reivo-guard provides budget enforcement, loop detection, anomaly detection, and more — all open source (MIT). The managed Reivo service adds smart routing, a dashboard, and Slack notifications on top.
What Reivo does NOT store
- - Prompt or completion content (forwarded and discarded)
- Conversation history
- Raw API keys in the database (encrypted at rest, decrypted only during proxying)
Reivo stores only: model name, token counts, cost, latency, timestamp, session/agent IDs, prompt hash (irreversible).
Behavior Guidelines
- - Always show costs in USD with 2 decimal places
- When budget is over 80%, proactively warn the user
- If an API call fails with 429 from Reivo proxy, explain it's a budget block (not rate limiting)
- Never expose the full API key in output — show only
rv_...xxxx (last 4 chars) - Suggest the dashboard for detailed analysis beyond what the API provides
Reivo — AI Agent 成本优化器
您现在已配备 Reivo,这是一个用于 AI API 调用的成本优化与保护层。
Reivo 的功能
Reivo 是一个透明代理,位于您的 Agent 与 LLM 提供商之间。它能够:
- - 路由至更便宜的模型 — 分析每个请求,选择能提供相同质量的最便宜模型(成本降低 40-60%)
- 实时追踪成本 — 按会话、Agent 和模型进行追踪
- 执行预算限制 — 当支出超过限额时阻止请求
- 检测失控循环 — 自动停止陷入无限循环的 Agent(哈希匹配 + TF-IDF 余弦相似度)
- 异常检测 — 基于 EWMA 的峰值检测标记异常使用模式
- 优雅降级 — 4 级渐进式响应(正常 → 激进路由 → 仅新会话 → 阻止)
- 发送 Slack 警报 — 预算警告、循环检测和异常通知
防护引擎是开源的:reivo-guard(TypeScript + Python)。
配置
用户的 Reivo API 密钥可通过 $REIVOAPIKEY 获取。
代理基础 URL(使用这些替代直接提供商 URL):
- - OpenAI:https://proxy.reivo.dev/openai/v1
- Anthropic:https://proxy.reivo.dev/anthropic/v1
- Google:https://proxy.reivo.dev/google/v1beta
仪表盘: https://app.reivo.dev
可用命令
当用户询问成本、预算或 Reivo 时,请使用以下命令:
检查成本
当用户询问我花了多少钱?、显示成本、成本报告或类似问题时:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/overview?days=7
以以下方式呈现响应:
- - 该期间的总支出
- 每日成本明细(以简单文本图表形式)
- 按成本排序的顶级模型
- 请求数量
检查防御状态
当用户询问预算状态、我安全吗?、循环状态或类似问题时:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/defense-status
以以下方式呈现:
- - 预算:$X.XX / $Y.YY(Z%)附带视觉进度条
- 检测到的循环:今日 N 个,本周 N 个
- 被阻止的请求:今日 N 个,本周 N 个
获取优化建议
当用户询问如何节省?、优化建议、降低成本或类似问题时:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/optimization
呈现每条建议,包括严重程度、描述和预估节省金额。建议包括:
- - 提示缓存 — 可使用缓存的重复提示
- 最大令牌浪费 — 使用不到其 max_tokens 预算 20% 的请求
- 未使用的工具 — 已发送但从未被调用的工具定义
设置预算
当用户说将预算设置为 50 美元、限制支出或类似内容时:
bash
curl -s -X POST \
-H Authorization: Bearer $REIVOAPIKEY \
-H Content-Type: application/json \
-d {budgetLimitUsd: 50} \
https://app.reivo.dev/api/v1/settings
确认预算已设置,并解释一旦达到限额,请求将被阻止。
清除预算
当用户说移除预算、清除限制或类似内容时:
bash
curl -s -X POST \
-H Authorization: Bearer $REIVOAPIKEY \
-H Content-Type: application/json \
-d {budgetLimitUsd: null} \
https://app.reivo.dev/api/v1/settings
设置路由模式
当用户说激进模式、质量模式或更改路由时:
bash
curl -s -X POST \
-H Authorization: Bearer $REIVOAPIKEY \
-H Content-Type: application/json \
-d {routingMode: aggressive} \
https://app.reivo.dev/api/v1/settings
模式:aggressive(最大化节省)、balanced(默认)、quality(优先使用原始模型)。
配置 Slack 通知
当用户说设置 Slack、在 Slack 上通知我或类似内容时:
bash
curl -s -X POST \
-H Authorization: Bearer $REIVOAPIKEY \
-H Content-Type: application/json \
-d {slackWebhookUrl: https://hooks.slack.com/services/...} \
https://app.reivo.dev/api/v1/settings
管理提供商 API 密钥
出于安全考虑,提供商密钥应通过仪表盘管理:
添加或轮换提供商密钥请访问: https://app.reivo.dev/settings
密钥在静态时加密,绝不会在 API 响应中暴露(显示为掩码形式,例如 sk-abc1...xyz9)。
为获得最大安全性,请创建专用于 Reivo 的限定范围或项目范围的密钥。
列出当前配置的密钥:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/provider-keys
查看 Agent 明细
当用户询问哪个 Agent 花费最多?、按 Agent 查看成本或类似问题时:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/agents?days=30
呈现按 Agent 和按模型的成本明细。
月度报告
当用户询问月度报告、本月支出或类似问题时:
bash
curl -s -H Authorization: Bearer $REIVOAPIKEY \
https://app.reivo.dev/api/v1/overview?days=30
打开仪表盘
当用户说打开仪表盘、显示仪表盘或我想要更多详情时:
Reivo 仪表盘: https://app.reivo.dev
登录后即可查看交互式成本图表、会话回放、循环检测历史和优化建议。
设置说明
如果用户尚未设置 Reivo,请指导他们:
- 1. 注册 访问 https://app.reivo.dev
- 生成 API 密钥 在设置中(格式:rv_...)
- 设置环境变量:
bash
export REIVO
APIKEY=rv
yourkey_here
- 4. 添加提供商密钥 通过仪表盘 https://app.reivo.dev/settings(出于安全考虑推荐 — 密钥在静态时加密)
- 通过代理路由 API 调用 更改提供商配置中的基础 URL。
对于 OpenClaw 特别说明,更新提供商配置:
json
{
providers: [
{
name: openai,
apiKey: ${REIVOAPIKEY},
baseUrl: https://proxy.reivo.dev/openai/v1
},
{
name: anthropic,
apiKey: ${REIVOAPIKEY},
baseUrl: https://proxy.reivo.dev/anthropic/v1
}
]
}
代理使用您注册的提供商密钥将请求转发到真实的提供商。您的原始 API 密钥永远不会离开 Reivo 服务器。
自托管防护
想要不使用代理的防护?直接使用 reivo-guard:
bash
pip install reivo-guard # Python
npm install reivo-guard # TypeScript
reivo-guard 提供预算执行、循环检测、异常检测等功能 — 全部开源(MIT)。托管版 Reivo 服务在此基础上增加了智能路由、仪表盘和 Slack 通知。
Reivo 不存储的内容
- - 提示或完成内容(转发后丢弃)
- 对话历史
- 数据库中的原始 API 密钥(静态加密,仅在代理期间解密)
Reivo 仅存储:模型名称、令牌计数、成本、延迟、时间戳、会话/Agent ID、提示哈希(不可逆)。
行为指南
- - 始终以美元显示成本,保留 2 位小数
- 当预算超过 80% 时,主动警告用户
- 如果 API 调用因 Reivo 代理返回 429 而失败,解释这是预算阻止(而非速率限制)
- 绝不在输出中暴露完整的 API 密钥 — 仅显示