惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
量子位
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
爱范儿
爱范儿
博客园 - 【当耐特】
Vercel News
Vercel News
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
博客园 - 叶小钗
博客园_首页
V
Visual Studio Blog
宝玉的分享
宝玉的分享
B
Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
V
V2EX

Hacker News - Newest: "AI"

AI can't read an investor deck AI as an attorney? Student uses ChatGPT, Gemini to sue UW over alleged racial discrimination Hacking MCP Servers in AI Systems – The Rug Pull: Tool Changes After Approval GitHub - MeepCastana/KubeezCut: Free Web based video editor Can AI judge journalism? A Thiel-backed startup says yes, even if it risks chilling whistleblowers Coming soon: 10 Things That Matter in AI Right Now DARPA built an AI to fact-check enemy weapons claims What explains heterogeneity in AI adoption? When AI Meets Muscle: Context-Aware Electrical Stimulation Promises a New Way to Guide Human Movements - Department of Computer Science AI Changed How We Build. It Did Not Change What Matters. Linux rules on using AI-generated code - Copilot is OK, but humans must take 'full responsibility for the… Meta spins up AI version of Mark Zuckerberg to engage with employees Code Mode: Let Your AI Write Programs, Not Just Call Tools | TanStack Blog GitHub - Delavalom/graft: Go framework for building AI agents. Type-safe tools, multi-provider (OpenAI, Anthropic, Gemini, Bedrock), zero vendor SDKs. India's TCS tops estimates, says new AI models did not dent services demand Gen Z's fading AI hype Strong feeling: we are in a folded AI reality GitHub - machinarii/total-recall-catalog: A reference catalog of latest knowledge retrieval, memory & RAG systems GitHub - mensfeld/code-on-incus: Give each AI agent its own isolated machine with root, Docker, and systemd. Active defense detects and stops threats automatically.. Quantization, LoRA, and the 8% Problem: Benchmarking Local LLMs for Production AI Iran war: We spoke to the man making Lego-style AI videos that experts say are powerful propaganda Powell, Bessent discussed Anthropic's Mythos AI cyber threat with major U.S. banks GitHub - immartian/bellamem: Persistent belief-graph memory for AI agents. Retrieves decisive context by importance — not recency, not RAG, not /compact. recursive-mode: The Repo-Native Operating System for AI Engineering After the attack on Sam Altman's home, will AI CEO's go on the offensive? The biggest advance in AI since the LLM Opus 4.6 vs GPT 5.4 One Prompt Unity World Generation Test “AI polls” are fake polls Client Challenge Can AI be a 'child of God'? Inside Anthropic's meeting with Christian leaders
GitHub - Reactance0083/pydantic-ai-multi-llm-cost-optimiz...
reactance008 · 2026-06-23 · via Hacker News - Newest: "AI"

Routes every prompt to the cheapest model that can handle it well. Uses pydantic-ai for the routing decision and litellm for unified execution across Claude, GPT-4o, and Groq. Tracks cost per model with a live /stats endpoint.

What It Does

  1. Receives a prompt with a quality tier (fast / standard / quality / max)
  2. Routes to the cheapest appropriate model using claude-haiku-4-5 as the router
  3. Executes via litellm (handles auth + API differences for all providers)
  4. Returns the response with cost breakdown and latency

Quick Start

pip install -r requirements.txt
cp .env.example .env
# Fill in at minimum ANTHROPIC_API_KEY. OPENAI and GROQ are optional.
uvicorn main:app --reload --port 8002

API Usage

POST /complete

curl -X POST http://localhost:8002/complete \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Summarize the key differences between REST and GraphQL",
    "quality": "standard",
    "task_type": "general"
  }'

Response:

{
  "text": "...",
  "model_used": "anthropic/claude-haiku-4-5",
  "input_tokens": 42,
  "output_tokens": 218,
  "cost_usd": 0.000283,
  "latency_ms": 847
}

GET /stats

{
  "models": {
    "anthropic/claude-haiku-4-5": {"calls": 47, "total_cost": 0.0134, "total_tokens": 52400}
  },
  "total_cost_usd": 0.0134,
  "total_calls": 47
}

Cost Table (May 2026)

Model Input/1k Output/1k Best For
groq/llama-3.1-8b-instant $0.00005 $0.00008 Fast, simple tasks
anthropic/claude-haiku-4-5 $0.00025 $0.00125 Structured outputs, classification
openai/gpt-4.1-mini $0.0004 $0.0016 General tasks, good value
anthropic/claude-sonnet-4-6 $0.003 $0.015 Code, complex reasoning
openai/gpt-4.1 $0.002 $0.008 Complex tasks
anthropic/claude-opus-4-7 $0.015 $0.075 Hardest tasks only
openai/gpt-5.5 $0.005 $0.015 Flagship reasoning, hardest tasks

Quality Tiers

Tier Models Considered Use When
fast Groq llama-8b, Claude haiku Low-stakes, high-volume, simple classification
standard Groq llama-70b, GPT-4o-mini, Claude haiku Most production tasks
quality Claude sonnet, GPT-4o Code generation, complex analysis
max Claude opus Hardest problems, highest stakes

Structured Routing (pydantic-ai)

class RoutingDecision(BaseModel):
    model: str           # exact litellm model string
    reason: str          # 1-sentence justification
    expected_tokens: int # rough output estimate

Architecture

POST /complete
  → routing agent (claude-haiku-4-5) → RoutingDecision
  → litellm.completion(model=decision.model, ...)
  → cost calculation → response + /stats update

Requirements

  • Python 3.11+
  • Anthropic API key (required)
  • OpenAI API key (optional, enables GPT routing)
  • Groq API key (optional, enables cheapest tier)

Get the Complete Bundle

All 5 templates are available individually or as a $39 bundle (saves $15 vs individual).

Template Price Link
Slack → Notion Automation $9 Buy on Gumroad
GitHub Issue → Linear Triage $9 Buy on Gumroad
Multi-LLM Cost Optimizer $12 Buy on Gumroad
Web Scraper + Semantic Search $9 Buy on Gumroad
Prompt Engineering Runbook $15 Buy on Gumroad
Complete Bundle (all 5) $39 Buy on Gumroad

Buying includes: all source files, README, requirements.txt, .env.example, and lifetime updates.

Free to use — the source is here on GitHub. Buying supports continued development and gets you a clean download with everything packaged.


Built by Wade Allen — AI Workflow Architect