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

推荐订阅源

J
Java Code Geeks
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
C
Check Point Blog
P
Proofpoint News Feed
H
Help Net Security
月光博客
月光博客
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
U
Unit 42
美团技术团队
I
InfoQ
A
About on SuperTechFans

Show HN

Show HN: AI agents for UK GDAD PCF roles and their skills The Two Pillars: Mixer Mode and Meta-Software in the Reorganization of Software Work After AI GitHub - JaiCode08/teleport-env What 1,000+ Harness Experiments Taught Me About Self-Improving Agents Show HN: Liiists, a Markdown-first, iOS and CLI list app SwiperTab – Get this Extension for 🦊 Firefox (en-US) GitHub - kouhxp/fftext: Summarize, explain, fact-check, or translate any text, URL, or file. No GPU. No cloud. One command GitHub - sweetpad-dev/sweetpad: Develop Swift/iOS projects using VSCode GitHub - dogmaticdev/IRON: IRON a.k.a. Intermediate Representation Object Notation is a Interpreter/Database that is used to create Programming Languages. GitHub - sjhalani7/vaen: Package your AI coding harness into a portable .agent file, and share it across repos, teams, & the community without ever having to copy-paste instructions, skills, MCP config, or secrets. Show HN: Gandalf the Grader Show HN: Citadeld – replay any CI failure locally from a single file GitHub - tdortman/cuSBF: High-Performance GPU Super Bloom Filter coral-ai/claude-code-token-xray at main · Coral-Bricks-AI/coral-ai GitHub - ulyssestenn/funes: Funes is a Git-based framework for LLM-managed knowledge work: an AI Librarian ingests raw sources, builds an interlinked Markdown knowledge base, and uses it to produce cited reports, analyses, and other outputs. GitHub - ThatXliner/gah: Git Add Hunk, built for agents to use GitHub - harmont-dev/harmont-cli: Command-line client for the Harmont CI platform GitHub - brooksmcmillin/mcp-authflow: OAuth 2.0 Authorization Server framework for MCP servers GitHub - javaid-codes/audit-supply-chain-agents GitHub - amorey/gochan: A small library of common channel architectures for Go, inspired by Rust GitHub - arifozgun/OpenGem: Free, Open-Source AI API Gateway with Gemini, OpenAI & Anthropic Compatibility in 1 file GitHub - Pranesh950/BioPetals: 🌸 Run BIOxAI models at home, BitTorrent-style. Fine-tuning and inference up to 10x faster than offloading GitHub - cnguyen14/bounty-doctor: Diagnose a GitHub bounty issue before you waste hours: detects honeypot scam repos, AI-bot attempt swarms, and stale contests. Show HN: CoreMCP – MCP Server for On-Prem DBs Show HN: KittyHTML – Render HTML/CSS as an inline image in your terminal GitHub - bingud/filemat: Web-based file manager Show HN: TruthLens – Free multi-signal deepfake image detector GitHub - apexlocal-jz/claude-usage-tray: Windows system-tray app showing your Claude Code rate-limit usage at a glance. Zero deps, ~300 lines of PowerShell. Cross-IDE (works regardless of VS Code, Cursor, plain terminal). Release v0.1.2.1 · kouhxp/yapsnap GitHub - noopolis/moltnet: Self-hostable chat network for AI agents. Pre-built bridges for Claude Code, Codex, and the Claws. Rooms, DMs, history. No Slack bots, no Matrix, no glue code.
GitHub - MordechaiHadad/rustgate: A rust powered token-aw...
MordechaiHad · 2026-06-02 · via Show HN

Rustgate Backend

Small FastAPI backend that uses a Rust pyo3 extension for AI token-aware rate limiting backed by Redis.

Summary

This repository contains two parts:

  • bindings/ -- a Rust crate that exposes Python bindings via pyo3/maturin
  • backend/ -- a small FastAPI app that loads the compiled extension and serves a few endpoints

The Rust extension uses the axum-rate-limiter crate and OpenAI's tiktoken-rs to count query tokens. Rate limits are applied per model and per sliding window, using the query's estimated token count multiplied by a model-specific cost factor.

Prerequisites

  • Rust toolchain (rustc/cargo)
  • Python 3.10+
  • uv (the uv dependency manager)
  • Redis (running on default port 6379, or configure with RUSTGATE_REDIS_URL)

Quick Start

  1. Ensure uv is installed and available on PATH.

  2. Install dependencies and build everything via uv:

    uv sync

    "uv sync" installs pinned dependencies from uv.lock and runs the build steps for this repository, including building the Rust pyo3 extension and installing the local Python package into the environment uv manages.

Run the server

After uv sync completes you can start the FastAPI server with uv:

uv run uvicorn main:app --app-dir src --host 127.0.0.1 --port 8001

This uses the environment and commands declared in the repo's uv configuration.

Environment

  • RUSTGATE_REDIS_URL -- redis connection string used by the rate limiter (default: redis://127.0.0.1:6379/0)

API Endpoints

All POST endpoints accept a JSON body with a query field, parsed by the Rust layer for token counting.

  • GET /health -- basic health check, returns {"status": "ok"}

  • POST /models/auto -- tries gpt-5 first, falls back to gpt-4 if rate limited. Returns {"model": "<model_name>"}.

  • POST /models/gpt-5 -- attempts to use gpt-5. Returns 429 if rate limited.

  • POST /models/gpt-4 -- attempts to use gpt-4. Returns 429 if rate limited.

Rate Limiting

Rate limits are enforced in Rust via the RedisAiLimiter (axum-rate-limiter crate) with the following rules:

  • Sliding window: 10 minutes (600 seconds).
  • Total budget: 5000 charge units per window per client, identified by IP (X-Forwarded-For or remote address).
  • Per-token cost:
    • gpt-4 family: 1 charge unit per token
    • gpt-5 family: 25 charge units per token
  • Token counting: uses tiktoken-rs with the appropriate tokenizer (Cl100kBase for gpt-4, O200kBase for gpt-5).
  • Zero-token queries: bypass rate limiting entirely.

Example: a 200-token gpt-5 query costs 5000 charge units (200 x 25), consuming the entire budget. The same 200-token query against gpt-4 costs only 200 charge units (200 x 1).

Supported models

The Rust layer supports two model families:

  • gpt-4 and gpt-4.* (e.g. gpt-4, gpt-4.1)
  • gpt-5 and gpt-5.* (e.g. gpt-5, gpt-5.4)

Models like gpt-4o, gpt-4o-mini, gpt-5-mini, or o3 are not currently supported and will return a 400 error.

Benchmark (sample load test)

Load test with oha against the POST /models/auto endpoint:

oha -z 30s -c 100 -m POST -d '{"query": "This is my grand query"}' \
  http://localhost:8001/models/auto

Results:

Metric Value
Duration 30.01 s
Requests/sec 1128.10
Fastest latency 15.34 ms
Average latency 88.76 ms
Slowest latency 774.95 ms
p50 75.0 ms
p90 152.1 ms
p95 168.36 ms
p99 183.6 ms
Rate-limited (429) 33713
Successful (200) 40

Comparison with the lightweight GET /health endpoint (no rate limiting, no token counting, no model rerouting, just a fast return):

oha -z 30s -c 100 -m GET http://localhost:8001/health
Metric Value
Duration 30.00 s
Requests/sec 1496.39
Fastest latency 13.70 ms
Average latency 66.90 ms
Slowest latency 1.89 s
p50 51.10 ms
p90 58.80 ms
p95 73.40 ms
p99 656.30 ms
Successful (200) 44796