LayerFlow documentation

Build, organize, and control everything you do with AI.

Start with the visual workspace, then connect your applications through one gateway. This guide explains the product, authentication, provider keys, budgets, and API without assuming infrastructure experience.

Overview

Four connected parts, one workspace

LayerFlow keeps prompt organization, model decisions, spending, and application traffic connected. A model call made from the workspace or gateway writes to the same run history and cost ledger.

Prompt Workspace

Organize prompts into domains, projects, and folders. Every save creates an immutable version you can compare or restore.

Model Intelligence

Estimate tokens and cost, compare providers, and get an explained recommendation for the cheapest suitable model.

Cost Control

Set daily or monthly hard limits. LayerFlow reserves estimated cost before a call and settles the actual cost afterward.

AI Gateway

Use one OpenAI-compatible endpoint with LayerFlow API keys while keeping provider billing in your own accounts.

Quickstart

Start in three steps

Use the workspace without writing code. Add an API key only when you want LayerFlow to call a model or serve requests from your application.

  1. 1

    Sign in with Google

    Open /sign-in and continue with Google. LayerFlow creates your account, default workspace, settings, budget, and starter domains.

  2. 2

    Add a provider key

    Open Settings → Provider keys and add your OpenAI, Anthropic, Gemini, or another supported provider key. It is encrypted before storage.

  3. 3

    Create and run a prompt

    Save a prompt, choose a model, review the token and cost estimate, then run or compare it.

Full workflow

From first login to gateway key

Follow this order the first time you use LayerFlow. You can always return to Settings to rotate keys or raise budgets.

  1. 1

    Sign in

    Use Continue with Google. After the OAuth callback you land in the workspace home.

  2. 2

    Create a project and prompt

    Pick a domain (Coding, Marketing, …), create a project, then New prompt. Every save writes an immutable Timeline version.

  3. 3

    Connect a provider key

    Settings → Provider keys. Paste your BYOK secret once. LayerFlow never returns the full key later.

  4. 4

    Get a model suggestion

    Open a prompt — the analysis panel estimates tokens/cost and recommends a cheaper suitable model.

  5. 5

    Run and compare

    Run uses your selected model with hard budget checks. Compare polls a background job across multiple models.

  6. 6

    Set a budget

    Cost / Budget → update monthly and daily limits. When the cap is hit, runs return 402 before the provider is called.

  7. 7

    Create a LayerFlow gateway key

    Settings → Create key. Copy the lf_ secret immediately, then call https://api.layerflow.dev/v1 from your app.

Prompt workspace

Your prompt history stays understandable

Domains contain projects, projects contain folders, and folders contain prompts. Prompts have immutable versions, so restoring an older version creates a new entry instead of deleting history.

Domain
Project
Folder
Prompt
Version
  • Search by title, body, tag, domain, project, or folder
  • Restore without rewriting history
  • Group prompts into ordered sessions
  • Compare cost, latency, and output quality

Models and BYOK

Your provider accounts, protected

BYOK means Bring Your Own Key. LayerFlow uses your provider account for billing and stores the key encrypted with AES-256-GCM. Raw keys are never returned by the API or written to logs.

Provider key

Authorizes LayerFlow to call OpenAI, Anthropic, Gemini, DeepSeek, Groq, xAI, or OpenRouter for your workspace.

LayerFlow key

Starts with lf_live_ and authorizes your application to use the LayerFlow gateway.

AI gateway

One endpoint for every supported model

Point an OpenAI-compatible client at LayerFlow, send your LayerFlow API key, and keep the familiar chat-completions request shape.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.LAYERFLOW_API_KEY,
  baseURL: "https://api.layerflow.dev/v1",
});

const result = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Explain this simply." }],
});
curl https://api.layerflow.dev/v1/chat/completions \
  -H "Authorization: Bearer lf_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Hello"}]}'

Hard budgets

Block overspend before the provider call

LayerFlow checks workspace, project, and API-key limits before sending a paid request. Cost is tracked in integer micro-dollars to avoid floating-point accounting errors.

1. Reserve

Atomically reserve the estimated maximum cost in Redis.

2. Execute

Call the selected provider only when the budget permits it.

3. Settle

Replace the estimate with actual usage and write the durable ledger.

API reference

Core endpoints

Workspace endpoints use the secure Google session cookie. Public gateway endpoints use a LayerFlow bearer key. All errors follow the same JSON error shape.

WorkspaceGET /api/workspaces/currentRead the active workspace
PromptsGET /api/promptsSearch and filter saved prompts
PromptsPOST /api/promptsCreate a prompt and version 1
VersionsPOST /api/prompts/:id/versionsSave an immutable version
RunsPOST /api/runsRun a prompt with a selected model
ComparePOST /api/compareCompare one prompt across models
IntelligencePOST /api/intelligence/analyzeEstimate tokens, cost, and task type
BudgetsGET /api/budgets/currentRead limits and current spend
KeysPOST /api/keysCreate a LayerFlow gateway key
GatewayPOST /v1/chat/completionsOpenAI-compatible model request
ModelsGET /v1/modelsList available models
SearchGET /api/search?q=...Search prompts and sessions
{
  "error": {
    "code": "budget_exceeded",
    "message": "This request would exceed the active budget."
  }
}

Local development

Run the API on your computer

Install Docker Desktop first. Postgres stores durable data, Redis handles live budgets and queues, and the API runs on port 8787.

npm install
docker compose up -d
cp apps/api/.env.example apps/api/.env
npm run db:migrate --workspace @layerflow/api
npm run db:seed --workspace @layerflow/api
npm run dev --workspace @layerflow/api

Start the worker in a second terminal with npm run worker --workspace @layerflow/api.

Ready to try LayerFlow?

Open the workspace to create your first project and prompt.

Sign in to open workspace