Skip to content

Repository files navigation

Gateway

Minimal OpenRouter chat app metered by Autumn's AI credit system (feat/ai-credit-system). One page: pick a mock customer, pick an OpenRouter model, send a prompt. The AI SDK model is wrapped with withAutumn from @useautumn/ai-sdk, which reports token usage to POST /v1/balances.track_tokens after every call. Autumn computes the dollar cost from models.dev pricing plus the markups in autumn.config.ts and deducts it from the customer's ai_credits balance.

Stack

Same as demos/rake: Next.js 16 + Tailwind v4 + shadcn/Base UI components, autumn-js, AI SDK v6. New here: @openrouter/ai-sdk-provider and a local file: link to autumn/packages/ai-sdk (unpublished).

autumn-js doesn't expose balances.trackTokens yet, so lib/autumn.ts shims it with a raw RPC call. Swap to the real client method once the SDK is regenerated.

Setup

# 1. Run the autumn server locally on :8080 from the feat/ai-credit-system branch

# 2. Configure env
cp .env.example .env.local   # add AUTUMN_SECRET_KEY (local org) + OPENROUTER_API_KEY

bun install

# 3. Push features/plans to the local server, then seed customers
bunx atmn push --local
bun run seed:customers

# 4. Run
bun run dev   # http://localhost:3006

Without AUTUMN_SECRET_KEY the app falls back to fixture customers and skips billing; without OPENROUTER_API_KEY chat requests fail.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages