13 KiB
External Integrations
Analysis Date: 2026-02-09
AI Model Providers
Flynn supports 10 model providers via a unified ModelClient interface (src/models/types.ts). Each provider implements chat() and optionally chatStream(). The ModelRouter (src/models/router.ts) manages tier-based routing (fast/default/complex/local) with fallback chains.
Anthropic:
- SDK:
@anthropic-ai/sdk(src/models/anthropic.ts) - Auth:
ANTHROPIC_API_KEYenv var orapi_keyin config - Features: Streaming, tool use, extended thinking mode, multimodal (images)
- Extended thinking:
{ type: 'enabled', budget_tokens: 4096 }on request
OpenAI:
- SDK:
openai(src/models/openai.ts) - Auth:
OPENAI_API_KEYenv var orapi_keyin config - Features: Tool use, multimodal (images via data URIs or URLs)
- Also powers: OpenRouter, ZhipuAI, xAI via
baseURLoverride
Google Gemini:
- SDK:
@google/generative-ai(src/models/gemini.ts) - Auth:
GOOGLE_API_KEYenv var orapi_keyin config - Features: Streaming, tool use, extended thinking, multimodal
AWS Bedrock:
- SDK:
@aws-sdk/client-bedrock-runtime(src/models/bedrock.ts) - Auth:
AWS_REGIONenv var + IAM credentials or explicitaccessKeyId/secretAccessKeyin config - Features: Streaming (ConverseStream), tool use, multimodal
- Models: Meta Llama, Amazon Titan (cost-tracked in
src/models/costs.ts)
GitHub Models (Copilot):
- SDK:
openai(OpenAI-compatible API) (src/models/github.ts) - Auth:
GITHUB_TOKENenv var or OAuth device flow (src/auth/github.ts) - Endpoint:
https://api.githubcopilot.com - Auto-fallback: When an Anthropic tier fails, Flynn automatically tries the same model via GitHub Models before the global fallback chain (
src/daemon/index.tscreateAutoFallbackClient()) - OAuth device flow: Uses client ID
Ov23li8tweQw6odWQebz, stores token at~/.config/flynn/auth.json
OpenRouter:
- SDK:
openaiwithbaseURL: https://openrouter.ai/api/v1(src/daemon/index.ts) - Auth:
OPENROUTER_API_KEYenv var orapi_keyin config
ZhipuAI:
- SDK:
openaiwithbaseURL: https://api.z.ai/api/paas/v4(src/daemon/index.ts) - Auth:
ZHIPUAI_API_KEYenv var orapi_keyin config
xAI (Grok):
- SDK:
openaiwithbaseURL: https://api.x.ai/v1(src/daemon/index.ts) - Auth:
XAI_API_KEYenv var orapi_keyin config
Ollama (Local):
- SDK:
ollama(src/models/local/ollama.ts) - Auth: None (local server)
- Endpoint: Configurable
host(default:http://localhost:11434) - Config:
num_gpuoption for GPU layer control
llama.cpp (Local):
- SDK: Raw
fetchHTTP calls (src/models/local/llamacpp.ts) - Auth: Optional
auth_tokenheader - Endpoint: Configurable (default:
http://localhost:8080)
Embedding Providers
Embedding providers (src/memory/embeddings.ts) power the hybrid vector + keyword search system. Factory function: createEmbeddingProvider().
OpenAI Embeddings:
- SDK:
openai(lazy import) - Auth:
OPENAI_API_KEYor configapi_key - Default model:
text-embedding-3-small, default dims: 1536
Gemini Embeddings:
- SDK:
@google/generative-ai(lazy import) - Auth:
GOOGLE_API_KEYor configapi_key - Uses
batchEmbedContentsfor efficiency, default dims: 768
Ollama Embeddings:
- SDK:
ollama(lazy import) - Auth: None (local)
- Configurable host endpoint, default dims: 768
LlamaCpp Embeddings:
- SDK: Raw
fetchto/embeddingendpoint - Auth: None
- Default endpoint:
http://localhost:8080, default dims: 768
Voyage AI Embeddings:
- SDK:
openai(OpenAI-compatible API, lazy import) - Auth:
VOYAGE_API_KEYenv var or configapi_key - Endpoint:
https://api.voyageai.com/v1, default dims: 1024
Data Storage
Session Database (SQLite):
- Library:
better-sqlite3(src/session/store.ts) - Location:
{dataDir}/sessions.db - Schema:
messagestable withid,session_id,role,content,created_at - TTL-based pruning: Configurable via
sessions.ttl(default: 30 days), hourly cleanup
Vector Database (SQLite):
- Library:
better-sqlite3(src/memory/vector-store.ts) - Location:
{dataDir}/vectors.db - Stores embedding chunks as
Float32ArrayBLOBs - Content hashing for deduplication
- Background indexer runs every 30 seconds
Memory Store (Filesystem):
- Location:
{dataDir}/memory/(src/memory/store.ts) - Format: Markdown files organized by namespace
- Layout:
global.md,user.md,sessions/{id}.md - Hybrid search: Keyword + vector (configurable weight via
hybrid_weight, default 0.7)
File Storage:
- Local filesystem only — no cloud object storage
Caching:
- In-memory response cache for web fetch tool (5-minute TTL) (
src/tools/builtin/web-fetch.ts) - No external cache service (Redis, etc.)
Channel Adapters (Messaging Platforms)
All adapters implement ChannelAdapter interface (src/channels/types.ts): connect(), disconnect(), send(), onMessage().
Telegram:
- SDK:
grammy(src/channels/telegram/) - Auth: Bot token via
telegram.bot_tokenconfig - Features: Long polling, chat ID allowlist, mention requirement, pairing codes, image/audio attachments
Discord:
- SDK:
discord.js(src/channels/discord/) - Auth: Bot token via
discord.bot_tokenconfig - Features: Guild/channel allowlists, mention requirement, pairing codes
Slack:
- SDK:
@slack/bolt(src/channels/slack/) - Auth:
bot_token,app_token,signing_secretin config - Features: Socket mode, channel allowlists, mention requirement, pairing codes
WhatsApp:
- SDK:
whatsapp-web.js(src/channels/whatsapp/) - Auth: QR code scanning (web client emulation)
- Features: Number/group allowlists, mention requirement, custom data directory, pairing codes
WebChat:
- Implementation: Gateway WebSocket bridge (
src/channels/webchat/) - Auth: Gateway token or Tailscale identity
- UI: Vanilla JS dashboard at
src/gateway/ui/(HTML + CSS + JS, no framework)
Authentication & Identity
GitHub OAuth (Device Flow):
- Implementation:
src/auth/github.ts - Client ID:
Ov23li8tweQw6odWQebz(GitHub Copilot) - Flow: Device code → User authorization → Token polling
- Storage:
~/.config/flynn/auth.json(600 permissions) - Priority:
GITHUB_TOKENenv → stored OAuth token →null
Gateway Auth:
- Static bearer token (
server.tokenin config) - Tailscale identity header trust (
server.tailscale_identity) - HTTP auth optional (
server.auth_http) - Gateway lock: Single-client WebSocket mode (
server.lock)
DM Pairing Codes:
- Implementation:
src/channels/pairing.ts,src/session/store.ts(SQLite persistence) - Purpose: Authenticate unknown senders via one-time codes
- Config:
pairing.enabled,pairing.code_ttl(default 5m),pairing.code_length(default 6) - Gateway handlers for code generation/verification
- TUI
/paircommand execution (generate/list/revoke) insrc/frontends/tui/minimal.ts - Persistence:
PairingStoreinterface with SQLitepairing_approvedtable -- approved senders survive daemon restarts
Gmail OAuth2:
- SDK:
googleapis(src/automation/gmail.ts) - Credentials:
~/.config/flynn/gmail-credentials.json - Token:
~/.config/flynn/gmail-token.json - Setup:
flynn gmail-authCLI command
Automation
Cron Scheduler:
- Library:
croner(src/automation/cron.ts) - Config:
automation.cron[]— each job hasname,schedule,message,output.channel,output.peer - Implements
ChannelAdapterto inject cron-triggered messages into the channel registry - Features: Enable/disable per job, timezone support, runtime management tools
Webhooks:
- Implementation:
src/automation/webhooks.ts - Auth: HMAC-SHA256 signature verification (
X-Webhook-Signatureheader) - Templates:
{{body}}and{{json.field}}placeholders - Route:
POST /webhooks/{name}on the gateway HTTP server - Config:
automation.webhooks[]withname,secret,message,output
Gmail Watcher:
- SDK:
googleapis(src/automation/gmail.ts) - Modes: Pub/Sub push notifications or polling fallback
- Pub/Sub topic:
projects/flynn-agent/topics/gmail-push - Watch renewal: Every 6 days (Google watch expires at ~7 days)
- Config:
automation.gmailwithwatch_labels,poll_interval,history_start - Route:
POST /gmail/pushon gateway for Pub/Sub push
Heartbeat Monitor:
- Implementation:
src/automation/heartbeat.ts - Checks: gateway, model, channels, memory, disk
- Config:
automation.heartbeatwithinterval,checks,failure_threshold,disk_threshold_mb - Notification: Sends to configured channel/peer on failures
Web & Content Tools
Web Search (Brave / SearXNG):
- Implementation:
src/tools/builtin/web-search.ts - Brave Search API:
https://api.search.brave.com/res/v1/web/search- Auth:
X-Subscription-Tokenheader viaweb_search.api_key
- Auth:
- SearXNG: Self-hosted instance via
web_search.endpoint- Auth: None (private instance)
- Config:
web_search.provider(braveorsearxng),web_search.max_results
Web Fetch (Readability):
- Libraries:
linkedom,@mozilla/readability,turndown(src/tools/builtin/web-fetch.ts) - Features: HTML → Markdown conversion, article extraction, response caching (5min TTL)
- Truncation: 50,000 character max
Browser Automation:
- Library:
puppeteer-core(src/tools/builtin/browser/) - Config:
browser.executable_pathorbrowser.ws_endpoint - Features: Headless browsing, page management, screenshots
- Limits:
browser.max_pages(default 5),browser.default_timeout(default 30s)
Audio Transcription
Whisper-Compatible API:
- Implementation:
src/models/media.ts - Endpoint: Configurable via
audio.transcription_endpoint - Auth:
audio.transcription_api_key(Bearer token) - Model:
audio.transcription_model(default:whisper-1) - Supported formats: OGG, MP3, WAV, WebM, MP4, M4A
- Integration: Auto-transcribes audio attachments from channels before model processing
MCP (Model Context Protocol)
MCP Client:
- SDK:
@modelcontextprotocol/sdk(src/mcp/client.ts) - Transport: stdio (spawns external processes)
- Config:
mcp.servers[]withname,command,args,env,cwd - Bridge: MCP tools auto-registered in Flynn's tool registry (
src/mcp/bridge.ts) - Management:
McpManagerstarts/stops all configured servers (src/mcp/manager.ts)
Docker Sandbox
Per-Session Containers:
- Implementation:
src/sandbox/manager.ts,src/sandbox/docker.ts - Config:
sandbox.image(default:node:22-slim),sandbox.network(default:none),sandbox.memory_limit,sandbox.cpu_limit - Features: Lazily created per session, replaces
shell.execandprocess.starttools with sandboxed versions - Prerequisite: Docker daemon available
Networking & Exposure
Gateway Server:
- Protocol: WebSocket (JSON-RPC) + HTTP (
src/gateway/server.ts) - Default port: 18800
- Binding:
127.0.0.1(localhost only) or0.0.0.0 - Features: LaneQueue for request ordering, session bridge, static file serving for dashboard
Tailscale Serve:
- Implementation:
src/gateway/tailscale.ts - Purpose: Expose gateway HTTPS endpoint on tailnet
- Config:
server.tailscale.serve,server.tailscale.hostname,server.tailscale.port - Prerequisite: Tailscale CLI installed and daemon running
Monitoring & Observability
Error Tracking:
- None (console.error only)
Logging:
console.log/console.error/console.debugthroughout- No structured logging framework
Cost Tracking:
- Built-in:
src/models/costs.tswith per-million-token pricing for known models - Tracks: Anthropic, OpenAI, Gemini, xAI, Bedrock models
- GitHub Copilot models tracked at $0 (subscription-included)
- Usage exposed via
/usagecommand and gatewaysystem.usageRPC
CI/CD & Deployment
Hosting:
- Self-hosted (designed for personal deployment)
- Process supervisor expected for restarts (exit code 75 = restart signal)
CI Pipeline:
- Not detected in repository
Environment Configuration
Required env vars (minimum viable):
ANTHROPIC_API_KEY(or other model provider key)FLYNN_TELEGRAM_TOKEN(if using default Telegram channel)
Optional env vars (by feature):
OPENAI_API_KEY- OpenAI models and embeddingsGOOGLE_API_KEY- Gemini models and embeddingsGITHUB_TOKEN- GitHub Models / Copilot accessAWS_REGION- Bedrock regionOPENROUTER_API_KEY- OpenRouter accessZHIPUAI_API_KEY- ZhipuAI accessXAI_API_KEY- xAI (Grok) accessVOYAGE_API_KEY- Voyage AI embeddingsFLYNN_DATA_DIR- Custom data directory
Secrets location:
- API keys: YAML config (with
${ENV_VAR}expansion) or environment variables - OAuth tokens:
~/.config/flynn/auth.json(GitHub),~/.config/flynn/gmail-token.json(Gmail) .env.examplepresent at project root
Webhooks & Callbacks
Incoming:
POST /webhooks/{name}- Named webhooks with HMAC-SHA256 verification (src/automation/webhooks.ts)POST /gmail/push- Google Pub/Sub push notifications for Gmail (src/automation/gmail.ts)
Outgoing:
- None (no outbound webhooks — all communication goes through channel adapters)
Integration audit: 2026-02-09