MCPcopy
hub / github.com/cita-777/metapi

github.com/cita-777/metapi @v1.3.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.3.0 ↗
4,829 symbols 15,085 edges 862 files 14 documented · 0%
README

Metapi

A relay for relays — aggregate scattered AI relay stations into one unified gateway

Bring together all your New API / One API / OneHub / DoneHub / Veloera / AnyRouter / Sub2API sites

into one API Key, one endpoint, with automatic model discovery, smart routing, and cost optimization.

LINUX DO

GitHub Release GitHub Stars Ask DeepWiki Docker Pulls Docker Image License Node.jsTypeScript Deploy on Zeabur Deploy to Render

中文 | English

Docs · Quick Start · Deployment · Configuration · Client Integration · FAQ · Contributing


🌐 Live Demo

Try Metapi without deploying — full-featured demo instance:

🔗 Demo URL metapi-t9od.onrender.com
🔑 Admin Token 123456

⚠️ Security Notice: This is a public demo. Do NOT enter any real API keys, credentials, or site information. Data may be reset at any time.

ℹ️ Note: Demo runs on Render free tier + OpenRouter free models (only :free suffixed models available). First visit may take 30-60s to wake up.


About

The AI ecosystem is seeing a growing number of aggregation relay stations based on New API / One API and similar projects. Managing balances, model lists, and API keys across multiple sites is scattered and time-consuming.

Metapi acts as the Meta-Aggregation Layer on top of these relay stations, unifying multiple sites into one endpoint (with configurable per-project downstream API Keys) — all downstream tools (Cursor, Claude Code, Codex, Open WebUI, etc.) can seamlessly access all models. Currently supported upstream platforms:

Pain Point How Metapi Solves It
One key per site, tedious client config Unified proxy endpoint + optional per-project downstream keys — all site models auto-aggregated under /v1/*
No idea which site offers the cheapest model Smart routing auto-selects the optimal channel by cost, balance, and usage
Site goes down, manual switching is a hassle Auto-failover — failed channels cool down and traffic shifts automatically
Balances scattered everywhere Centralized dashboard — at-a-glance overview with low-balance alerts
Daily check-ins across sites Auto check-in — scheduled execution with reward tracking
Don't know which site has which models Auto model discovery — new upstream models appear with zero config

Screenshots

dashboard Dashboard — Balance distribution, spending trends, system overview model-marketplace Model Marketplace — Cross-site model coverage, pricing comparison, measured metrics
routes Smart Routing — Multi-channel probability distribution, cost-priority routing accounts Account Management — Multi-site multi-account, health state tracking
sites Site Management — Upstream site configuration and status overview tokens Token Management — API Token lifecycle management
playground Model Playground — Interactive online model testing checkin Check-in Log — Auto check-in status and reward tracking
proxy-logs Usage Logs — Proxy request logs and cost breakdown monitor Availability Monitor — Channel health real-time monitoring
settings System Settings — Global parameters and security configuration notification-settings Notification Settings — Multi-channel alert and push configuration

Architecture Overview

Downstream Clients (Cursor · Claude Code · Codex · Open WebUI · Cherry Studio, etc.)  ↓  Authorization: Bearer <PROXY_TOKEN> Metapi Gateway  • Unified /v1 proxy for core OpenAI / Claude-compatible endpoints (Responses, Chat Completions, Messages, Completions, Embeddings, Images, Models)  • Smart Routing Engine — weighted selection by cost, balance, and availability; auto-cooldown & retry on failure  • Model Discovery — auto-aggregates all upstream models with zero config  • Format Conversion — transparent bidirectional OpenAI ⇄ Claude conversion  • Auto Check-in · Balance Management · Alerts & Notifications · Data Dashboard  ↓ Upstream Platforms (New API · One API · OneHub · DoneHub · Veloera · AnyRouter · Sub2API …)


Features

Unified Proxy Gateway

  • Compatible with OpenAI and Claude downstream formats, works with all mainstream clients
  • Supports Responses / Chat Completions / Messages / Completions (Legacy) / Embeddings / Images / Models, plus standard /v1/files
  • Full SSE streaming support with automatic format conversion (OpenAI <-> Claude)

Smart Routing Engine

  • Auto-discovers all available models from upstream sites — zero-config route table generation
  • Four-tier cost signal: measured cost -> account-configured cost -> catalog reference price -> default fallback
  • Multi-channel probabilistic distribution weighted by cost (40%), balance (30%), and usage (30%)
  • Failed channels auto-cool down (default 10-minute cooldown)
  • Auto-retry on failure with automatic channel switching
  • Routing decisions are visually explainable — every choice is transparent and auditable

smart-routing-detail

Smart Routing UI — supports exact match, wildcards, probability distribution, and more routing strategies

Multi-Platform Aggregation

Platform Adapter Description
New API new-api Next-gen LLM gateway
One API one-api Classic OpenAI API aggregation
OneHub onehub Enhanced One API fork
DoneHub done-hub Enhanced OneHub fork
Veloera veloera API gateway platform
AnyRouter anyrouter Universal routing platform
Sub2API sub2api Subscription-based relay

Adapters cover shared capabilities such as model discovery, balance access, token management, and proxy integration; login, check-in, and user-info flows vary by platform.

Account & Token Management

  • Multi-site, multi-account: Each site supports multiple accounts, each account can hold multiple API tokens
  • Health tracking: healthy / unhealthy / degraded / disabled four-state machine
  • Encrypted credential storage: All sensitive credentials are encrypted in the local database
  • Auto-renewal: Tokens are automatically re-authenticated when expired
  • Cascading control: Disabling a site automatically disables all associated accounts

Model Marketplace

  • Cross-site model coverage overview: which models are available, how many accounts cover them, pricing comparison
  • Latency, success rate, and other measured metrics
  • Upstream model catalog caching with brand classification (OpenAI, Anthropic, Google, DeepSeek, etc.)
  • Interactive model tester for online verification

model-marketplace-detail

Model Marketplace — browse all available models' coverage, pricing, and performance metrics in one place

Auto Check-in

  • Cron-scheduled automatic check-in (default: daily at 08:00)
  • Smart reward parsing with failure notifications
  • Per-account execution with enable/disable control
  • Full check-in logging with history queries
  • Concurrency locking to prevent duplicate check-ins

Balance Management

  • Scheduled balance refresh (default: every hour), batch updates for all active accounts
  • Income tracking: daily/cumulative income with spending trend analysis
  • Balance fallback estimation: infer balance changes from proxy logs when API is unavailable
  • Auto re-login on credential expiry

Alerts & Notifications

Five notification channels supported:

Channel Description
Webhook Custom HTTP push
Bark iOS push notifications
ServerChan WeChat notifications
Telegram Bot Telegram message notifications
SMTP Email Standard email notifications

Alert scenarios: low balance warning, site/account anomalies, check-in failures, proxy request failures, token expiry reminders, daily summary reports. Alert cooldown mechanism (default: 300 seconds) prevents duplicate notifications.

Data Dashboard

  • Site balance pie chart, daily spending trend graphs
  • Global search (sites, accounts, models)
  • System event logs, proxy request logs (model, status, latency, token usage, cost estimation)

dashboard-detail

Data Dashboard — balance distribution, spending trends, system health at a glance

Model Playground

  • Interactive chat testing to instantly verify model availability and response quality
  • Select any routed model to compare outputs across different channels
  • Streaming / non-streaming dual mode testing

playground-detail

Model Playground — interactive online testing, verify model availability and response quality

Lightweight Deployment

  • Single Docker container with a default local data directory, plus optional external MySQL / PostgreSQL runtime DB
  • Docker images support amd64, arm64, and armv7l (linux/arm/v7) server deployments
  • Full data import/export for worry-free migration

Quick Start

Docker Compose (Recommended)

```bash mkdir metapi && cd metapi

cat > docker-compose.yml << 'EOF' services: metapi: image: 1467078763/metapi:latest port

Extension points exported contracts — how you extend this code

OAuthSessionStore (Interface)
(no doc) [2 implementers]
src/server/services/oauth/sessionStore.ts
Toast (Interface)
(no doc)
src/web/components/Toast.tsx
FixtureScriptOptions (Interface)
(no doc)
scripts/dev/generate-upgrade-fixture.ts
PlatformAdapter (Interface)
(no doc) [1 implementers]
src/server/services/platforms/base.ts
ToastContextValue (Interface)
(no doc)
src/web/components/Toast.tsx
ProxyAuthContext (Interface)
(no doc)
src/server/middleware/auth.ts
SiteResult (Interface)
(no doc)
src/web/components/SearchModal.tsx
ProxyResourceOwner (Interface)
(no doc)
src/server/middleware/auth.ts

Core symbols most depended-on inside this repo

get
called by 1553
src/server/services/oauth/sessionStore.ts
push
called by 784
src/server/services/platforms/newApi.ts
tr
called by 344
src/web/i18n.tsx
close
called by 202
src/server/db/runtimeSchemaBootstrap.ts
request
called by 137
src/web/api.ts
asNullableString
called by 108
src/server/services/databaseMigrationService.ts
upsertSetting
called by 79
src/server/db/upsertSetting.ts
asNumber
called by 69
src/server/services/databaseMigrationService.ts

Shape

Function 4,322
Method 310
Interface 119
Class 78

Languages

TypeScript100%

Modules by API surface

src/server/services/tokenRouter.ts155 symbols
src/server/services/platforms/newApi.ts72 symbols
src/server/services/backupService.ts72 symbols
src/server/transformers/shared/chatFormatsCore.ts70 symbols
src/web/pages/helpers/modelTesterSession.ts64 symbols
src/server/db/index.ts64 symbols
src/web/pages/OAuthManagement.tsx53 symbols
src/server/transformers/openai/responses/aggregator.ts50 symbols
src/server/services/modelPricingService.ts49 symbols
src/web/pages/ProxyLogs.tsx46 symbols
src/web/pages/Accounts.tsx46 symbols
src/server/transformers/anthropic/messages/stream.ts45 symbols

Dependencies from manifests, versioned

@dnd-kit/core6.3.1 · 1×
@dnd-kit/sortable10.0.0 · 1×
@dnd-kit/utilities3.2.2 · 1×
@electron/notarize3.1.0 · 1×
@fastify/cors11.2.0 · 1×
@fastify/static9.0.0 · 1×
@tailwindcss/vite4.2.2 · 1×
@types/node22.10.1 · 1×
@types/node-cron3.0.11 · 1×
@types/nodemailer7.0.11 · 1×
@types/pg8.20.0 · 1×

Datastores touched

(mysql)Database · 1 repos
metapiDatabase · 1 repos
dbDatabase · 1 repos
metapiDatabase · 1 repos
mysqlDatabase · 1 repos
dbDatabase · 1 repos
mydbDatabase · 1 repos
postgresDatabase · 1 repos

For agents

$ claude mcp add metapi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact