Spendex AI Router
Stop overpaying for AI. Spendex analyzes every prompt and routes it to the best model at the lowest cost — automatically.
Bring Your Own Keys — connect your existing OpenAI, Anthropic, Google, Mistral, DeepSeek, Groq, Together, Fireworks, Cohere keys in the Spendex dashboard. Spendex routes between them intelligently.
Setup
- 1. Create a free account at https://spendex.ai
- Connect your provider API keys in the dashboard (OpenAI, Anthropic, Google, etc.)
- Copy your Spendex API key (
spx_...) from the dashboard - Set it as an environment variable: INLINECODE1
Chat Completion
When the user asks you to generate text, answer questions, write code, or any task that requires an LLM — route the request through Spendex instead of calling providers directly.
Spendex automatically classifies prompt complexity (simple/medium/complex) and picks the best model+provider combo for cost and quality.
CODEBLOCK0
Replace USER_PROMPT_HERE with the actual user message.
The response includes:
- -
content — the AI response - INLINECODE4 — which model was selected by the router
- INLINECODE5 — exact cost in USD
- INLINECODE6 — money saved vs. using the most expensive model
- INLINECODE7 — prompt complexity (simple / medium / complex)
- INLINECODE8 — which provider served the request
Check Credit Balance
Show the user how much credit they have left.
CODEBLOCK1
Check Budgets
Show active budgets and how much has been spent vs. the limit.
CODEBLOCK2
Check Usage Stats
Show recent usage broken down by model and provider.
CODEBLOCK3
Check Cost Savings
Show how much money Spendex has saved compared to always using the most expensive model.
CODEBLOCK4
Tips
- - You can add a
"model" field to force a specific model (e.g. "model": "gpt-4o"), but leaving it empty lets Spendex pick the optimal one. - For conversations with history, include the full message array in
"messages". - Spendex deduplicates identical requests to avoid double-billing.
- If the user asks "how much am I spending?", use the balance + usage + savings endpoints to give a full picture.
Spendex AI 路由器
别再为AI多花钱了。Spendex会分析每个提示词,自动将其路由到成本最低的最佳模型。
自带密钥 — 在Spendex控制面板中连接您现有的OpenAI、Anthropic、Google、Mistral、DeepSeek、Groq、Together、Fireworks、Cohere密钥。Spendex会在它们之间智能路由。
设置
- 1. 在 https://spendex.ai 创建免费账户
- 在控制面板中连接您的提供商API密钥(OpenAI、Anthropic、Google等)
- 从控制面板复制您的Spendex API密钥(spx...)
- 将其设置为环境变量:export SPENDEXAPIKEY=spxyourkeyhere
聊天补全
当用户要求您生成文本、回答问题、编写代码或任何需要大语言模型的任务时 — 通过Spendex路由请求,而不是直接调用提供商。
Spendex会自动分类提示词复杂度(简单/中等/复杂),并选择最佳的模型+提供商组合,兼顾成本和质量。
bash
curl -s -X POST https://app.spendexai.com/v1/chat/completions \
-H Authorization: Bearer $SPENDEXAPIKEY \
-H Content-Type: application/json \
-d {
\messages\: [{\role\: \user\, \content\: \用户提示词\}],
\stream\: false
} | jq {
content: .choices[0].message.content,
model: .model,
cost: .usage.cost,
saved: .usage.saved,
classification: .usage.classification,
provider: .usage.provider
}
将用户提示词替换为实际的用户消息。
响应包含:
- - content — AI响应内容
- model — 路由器选择的模型
- cost — 精确成本(美元)
- saved — 与使用最昂贵模型相比节省的费用
- classification — 提示词复杂度(简单/中等/复杂)
- provider — 处理请求的提供商
查询信用余额
向用户显示剩余信用额度。
bash
curl -s https://app.spendexai.com/api/credits/balance \
-H Authorization: Bearer $SPENDEXAPIKEY | jq .
查询预算
显示活跃预算以及已花费金额与限额的对比。
bash
curl -s https://app.spendexai.com/api/budgets \
-H Authorization: Bearer $SPENDEXAPIKEY | jq .
查询使用统计
按模型和提供商显示近期使用情况。
bash
curl -s https://app.spendexai.com/api/usage/realtime?stats=true \
-H Authorization: Bearer $SPENDEXAPIKEY | jq .
查询成本节省
显示与始终使用最昂贵模型相比,Spendex节省了多少费用。
bash
curl -s https://app.spendexai.com/api/analytics/savings \
-H Authorization: Bearer $SPENDEXAPIKEY | jq .
提示
- - 您可以添加model字段来强制指定特定模型(例如model: gpt-4o),但留空则让Spendex选择最优模型。
- 对于包含历史记录的对话,请在messages中包含完整的消息数组。
- Spendex会去重相同的请求,避免重复计费。
- 如果用户问我花了多少钱?,请使用余额+使用量+节省端点来提供完整信息。