Skip to content

About

Open-source LLM distribution gateway and embeddable SDK for AI last-mile channels.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModelFaucet logo

English | 简体中文

ModelFaucet

Turn every app into an AI last-mile channel.
Chinese name: 模型水龙头.

ModelFaucet is an open-source LLM distribution gateway and embeddable SDK. It lets any website, app, plugin, desktop software, or vertical SaaS integrate AI features that feel native to the product, while automatically attributing token usage and revenue share to the software developer or distribution channel.

Status: v1.3.0-beta.1 construction candidate. Production entrypoints, migrations/restore, concurrency-safe settlement, owner-scoped usage, app/session controls, feature flags, dependency readiness, and three production images pass local plus Docker CI verification. Real hosted traffic remains blocked on tagged GHCR digest/provenance pull evidence plus managed DB/Redis/TLS, real-provider, alert-routing, soak, and rollback drills. See the capability matrix for the exact implemented, verified, and Beta-enabled surface.


What ModelFaucet does

ModelFaucet combines six things that are usually implemented separately:

1. Embeddable AI SDK         Add AI features inside any app.
2. LLM Gateway              Route to cloud providers through one API.
3. BYOK                     Let end users bring their own API keys.
4. Local Bridge             Support Ollama, vLLM, LM Studio, and LAN models.
5. Usage Ledger             Record token usage, cost, price, and margin.
6. Revenue Sharing          Automatically credit channel/developer wallets.

The goal is not to build another generic chatbot. The goal is to make every software product a distribution channel for vertical AI capabilities.


Core idea

Third-party App
  -> ModelFaucet SDK
  -> Session Broker
  -> Faucet Gateway
  -> Provider Router / LiteLLM / Local Bridge
  -> Usage Ledger
  -> Rating Engine
  -> Developer Revenue Wallet

End users can use AI in three ways:

Default faucet mode:    No API key needed. User buys credits or uses included quota.
BYOK mode:              User enters their own provider API keys.
Local mode:             User routes sensitive tasks to local or LAN models.

Developers can configure their app as a channel:

- Create app
- Get public_app_id
- Embed SDK
- Configure feature manifest
- Choose markup and revenue share
- Receive automatic revenue entries

Why this exists

Most LLM infrastructure products solve model access. They do not fully solve distribution economics.

ModelFaucet adds the missing layer:

LLM Gateway
+ vertical app SDK
+ end-user friendly AI UX
+ BYOK and local models
+ usage-based billing
+ channel attribution
+ automatic payout ledger

This lets a CRM, helpdesk, ecommerce admin, CMS, spreadsheet tool, browser extension, or desktop app become an AI distribution endpoint without rebuilding billing, key management, routing, and token accounting from scratch.


Architecture

+---------------------------------------+
| Third-party App / Website / Plugin    |
| @modelfaucet/sdk + UI Components      |
+-------------------+-------------------+
                    |
                    v
+---------------------------------------+
| Session Broker                        |
| app auth, user hash, feature policy   |
| ephemeral session token               |
+-------------------+-------------------+
                    |
                    v
+---------------------------------------+
| Faucet Gateway                        |
| OpenAI-compatible /v1                 |
| routing, fallback, budget, streaming  |
+-------+-------------------+-----------+
        |                   |
        v                   v
+---------------+     +----------------+
| LiteLLM Proxy |     | Local Bridge   |
| Cloud LLMs    |     | Ollama/vLLM    |
+-------+-------+     +-------+--------+
        |                     |
        v                     v
+---------------------------------------+
| Usage Meter + Rating Engine           |
| token count, cost, price, margin      |
+-------------------+-------------------+
                    |
                    v
+---------------------------------------+
| Ledger + Billing + Settlement         |
| wallets, revenue share, payout        |
+---------------------------------------+

MVP modules

apps/
  api/                 Control plane API: apps, users, keys, wallets, usage.
  gateway/             OpenAI-compatible request proxy and route selector.
  dashboard/           Developer console and admin dashboard.
  website/             Independent bilingual GitHub Pages website and scenario model.

packages/
  sdk-js/              Browser/server TypeScript SDK.
  react/               Drop-in React components.
  shared/              Shared types, schemas, and utilities.

services/
  local-bridge/        Local/LAN model bridge for Ollama, vLLM, LM Studio.
  rating-worker/       Token usage pricing and margin calculation.
  settlement-worker/   Reserved async package; settlement currently runs through the Control API.

infra/
  db/                  PostgreSQL schema and migrations.
  docker/              Local development compose files.

docs/
  WHITEPAPER.md        Human-readable project whitepaper.
  CONSTRUCTION.md      Codex-ready implementation guide.
  API_SPEC.md          Public and internal API specification.
  SECURITY.md          Security architecture and threat model.

Quickstart

The local stack uses PostgreSQL, Redis, and LiteLLM through Docker Compose.

# 1. Start dependencies
cp .env.example .env
docker compose up -d postgres redis litellm

# 2. Install packages
pnpm install

# 3. Run migrations and seed data
pnpm db:migrate
pnpm db:seed

# 4. Optional: run the local end-to-end smoke test
pnpm smoke:local

# 5. Start API, gateway, and dashboard
pnpm dev

# 6. Run CRM demo in another shell
pnpm --filter crm-demo dev

For a zero-secret local smoke path, pnpm smoke:local starts a local OpenAI-compatible mock provider and verifies session creation, gateway routing, usage recording, ledger entries, and dashboard aggregates.

For platform cloud routing, put a real test provider key in .env before using LiteLLM, for example OPENAI_API_KEY=<your-test-key>. Do not commit .env. Without a provider key, use BYOK, the Local Bridge, or the mock provider smoke path for end-to-end model calls.

Then in the demo app:

import { createFaucet } from "@modelfaucet/sdk";

const faucet = createFaucet({
  publicAppId: "app_pub_demo",
  user: { id: "demo-user-1" }
});

const result = await faucet.chat({
  feature: "customer_reply",
  input: {
    ticket_text: "客户说物流太慢,要求退款。"
  }
});

Expected behavior:

- SDK creates a short-lived session token.
- Gateway routes to the platform provider pool.
- A non-streaming response returns to the app (`stream: true` is currently rejected).
- usage_events receives a row.
- ledger_entries records user debit, provider cost, developer revenue, platform revenue.
- Developer dashboard shows usage and revenue.

Website and documentation

The repository includes an independent bilingual website plus the VitePress docs site for GitHub Pages.

pnpm website:build
pnpm docs:dev
pnpm docs:build
pnpm docs:preview
pnpm pages:build

The Pages workflow publishes a merged artifact from .pages-dist on pushes to main. The website owns the root page and scenario routes, while the documentation keeps stable paths such as /quickstart, /roadmap, and /zh-CN/.

The website scenario model is static and does not collect provider keys. Platform-route examples model explicit markup, BYOK examples model only visible gateway/product fees, and local examples model visible local software fees.

For deployment release checks:

pnpm db:verify-migrations
pnpm compose:verify
pnpm container:verify

Hosted API and Gateway deployments use REDIS_URL for distributed fixed-window rate limits across multiple instances. Without REDIS_URL, local development falls back to the in-memory limiter.

See the local smoke test guide for Docker Compose and non-Docker verification.

See the provider routing guide for LiteLLM timeout, retry, health-check, fallback, and real-provider smoke behavior.

See the SDK and Local Bridge guide for runFeature, React usage display, Local Bridge diagnostics, and offline local usage reporting.

See the operations guide for request IDs, readiness, metrics, rate limits, migration rollback, backup, and restore.

See the billing and settlement guide for Stripe webhook replay, ledger reconciliation, wallet adjustments, payout review, and CSV exports.

See the threat and abuse model for the current security invariants, SSRF controls, abuse cases, and release regression gates.

See the hosted beta guide for environment verification, tenant isolation checks, readiness smoke, pilot onboarding, acceptable use, and incident-response contacts.

See the capability matrix before integrating or publishing claims about the hosted Beta surface.

See the stability policy, migration and upgrade guide, production reference architecture, deployment validation guide, governance and support policy, and publishing strategy for the intended 1.x compatibility policy. Hosted GA has not been declared.


API compatibility

ModelFaucet exposes OpenAI-compatible endpoints where possible:

POST /v1/chat/completions   implemented; non-streaming only
POST /v1/responses          roadmap; not implemented
POST /v1/embeddings         roadmap; not implemented

It also exposes ModelFaucet-specific endpoints:

POST   /v1/sessions
GET    /ready
GET    /metrics
GET    /v1/user/wallet
POST   /v1/admin/wallets/:id/credit-test-balance
POST   /v1/user/provider-keys
GET    /v1/user/provider-keys
DELETE /v1/user/provider-keys/:id
GET    /v1/developer/apps
POST   /v1/developer/apps
PATCH  /v1/developer/apps/:publicAppId
DELETE /v1/developer/apps/:publicAppId
GET    /v1/developer/apps/:publicAppId/features
POST   /v1/developer/apps/:publicAppId/features
PATCH  /v1/developer/apps/:publicAppId/features/:featureKey
DELETE /v1/developer/apps/:publicAppId/features/:featureKey
GET    /v1/developer/operations
POST   /v1/developer/provider-keys
GET    /v1/developer/provider-keys
DELETE /v1/developer/provider-keys/:id
POST   /v1/user/stripe/checkout-sessions
POST   /v1/stripe/webhook
POST   /v1/admin/payouts/run-mock
POST   /v1/admin/payouts/:id/approve
POST   /v1/admin/payouts/:id/mark-paid
GET    /v1/admin/reconciliation/ledger
POST   /v1/admin/wallets/:id/adjustments
GET    /v1/admin/reports/usage.csv
GET    /v1/admin/reports/revenue.csv
GET    /v1/admin/reports/payouts.csv
GET    /v1/apps/:publicAppId/usage

Security model

Never put real provider API keys in client-side code.

The SDK may contain:

- public_app_id
- public gateway URL
- feature manifest
- ephemeral session token

The SDK must never contain:

- OpenAI API key
- Anthropic API key
- Gemini API key
- OpenRouter API key
- Cloud provider secret
- developer or end user raw secret after storage

Real secrets belong in a server-side vault or KMS. Browser and mobile clients only receive short-lived virtual sessions.

Local/LAN endpoints must be called through the Local Bridge. The cloud gateway must not directly access user private network addresses.


Revenue model

For platform faucet mode:

retail_price = upstream_cost × (1 + markup_percent)
gross_margin = retail_price - upstream_cost
developer_revenue = gross_margin × channel_share
platform_revenue = gross_margin - developer_revenue

For BYOK mode:

upstream_cost_to_modelfaucet = 0
revenue = explicit gateway fee / subscription fee only

For local mode:

upstream_cost_to_modelfaucet = 0
revenue = local bridge / enterprise management / support fee

Feature manifest example

app:
  name: Acme CRM AI
  vertical: crm

features:
  - key: customer_reply
    display_name: 客户回复生成
    input_schema:
      ticket_text: string
      customer_profile: object
    output_schema:
      reply: string
      risk_flags: array
    default_model_policy: cheapest_sufficient
    privacy_policy: redact_pii_before_cloud
    route_preference:
      - local
      - end_user_byok
      - developer_key
      - platform_pool
    pricing:
      mode: usage_markup
      markup_percent: 30
    revenue_share:
      channel_bps: 4000
      platform_bps: 6000

Development roadmap

Phase 0 - Spec package
  README, whitepaper, construction docs, API spec, DB schema.

Phase 1 - Minimum revenue loop
  SDK -> session -> gateway -> LiteLLM -> usage -> ledger -> dashboard.

Phase 2 - BYOK
  End-user provider key storage, verification, routing, and usage reporting.

Phase 3 - Local Bridge
  Ollama/vLLM/LM Studio support, local health checks, usage reporting.

Phase 4 - Developer provider keys
  Developer key vault, routing priority, budgets, fallback.

Phase 5 - Payments and payouts
  Credits, wallet, Stripe test mode, payout workflow.

Phase 6 - Public open-source launch
  Docker Compose, docs site, independent website, scenario demo, contribution guide.

Docs

Start here:

docs/WHITEPAPER.md
  Product vision, business model, and system architecture.

docs/index.md
  Documentation site homepage.

docs/quickstart.md
  Documentation site quickstart.

docs/CONSTRUCTION.md
  Build plan, repo structure, milestones, tasks, acceptance criteria.

docs/API_SPEC.md
  API contracts for SDK, gateway, BYOK, local bridge, ledger.

docs/SECURITY.md
  Threat model, secret handling, local network protection.

docs/CODEX_TASKS.md
  Task list and prompts for Codex implementation.

docs/RELEASE_CHECKLIST.md
  Prerelease and hosted production verification checklist.

docs/hosted-beta.md
  Hosted beta environment contract, reference Compose, AUP, and incident response.

docs/stability-policy.md
  Stable API, SDK, database migration, and security policies.

docs/migration-upgrade.md
  Upgrade, rollback, and fresh-install guidance for `1.x`.

docs/production-architecture.md
  Production reference architecture and operating expectations.

docs/deployment-validation.md
  Docker/Compose, secret manager, CORS, readiness, and database validation.

docs/governance-support.md
  Maintainership, support policy, release cadence, and security intake.

docs/publishing-strategy.md
  Source, npm package, container, and hosted deployment publishing strategy.

License

Apache-2.0. See LICENSE.


Project name note

A preliminary web search did not identify a major LLM infrastructure project with the exact name ModelFaucet. This is not a legal clearance. Before publishing packages, verify:

- GitHub organization availability
- npm package availability
- PyPI package availability
- Docker Hub / GHCR namespace
- Domain availability
- Trademark conflicts in target markets

Repository bootstrap checklist

[x] Create GitHub repo: HiClawBot/modelfaucet
[x] Add LICENSE
[x] Add CODE_OF_CONDUCT.md
[x] Add CONTRIBUTING.md
[x] Add SECURITY.md
[x] Add docs site config
[x] Add independent website and scenario demo
[x] Add pnpm workspace
[x] Add apps/api
[x] Add apps/gateway
[x] Add apps/dashboard
[x] Add packages/sdk-js
[x] Add packages/react
[x] Add infra/db migrations
[x] Add docker-compose.yml
[x] Add first CRM demo

Maintainer stance

ModelFaucet should be built with three hard rules:

1. No real provider keys in clients.
2. No hidden fees in BYOK mode.
3. No cloud-side access to user private networks.

About

Open-source LLM distribution gateway and embeddable SDK for AI last-mile channels.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages