Skip to content
DataKnifeAIPublic

About

Freya Studio API — HTTP /v1 backend and packs for Freya

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Freya API

Freya API

Freya automation API — the Studio brain for DataKnifeAI Freya. Routes natural-language sessions through OpenRouter (chat / assist / cloud generate), talks to the local diffusion worker for GPU stills and GIFs, owns gallery + Civitai install jobs, and serves the versioned /v1 contract that freya-web and freya-mcp consume. This repo builds Harbor image library/freya-api.

Meta compose/pins, stack docs, and the channel/compat scaffold live in freya-web (deploy/compose/, docs/stack/, channels/).

What it is

  • Rust freya-api binary on :8080 — /healthz + /v1/*
  • Runtime instruction packs under packs/ (FREYA_PACKS_DIR) for converse / draft / plan tones
  • Optional bearer (FREYA_API_TOKEN) or admin login; unset both → open /v1 for local/dev only
  • Calls freya-worker at FREYA_DIFFUSION_WORKER_URL (same FREYA_WORKER_TOKEN when set)

Relation to other components

Component Role vs this API
freya-web Studio UI — HTTP /v1/* (+ /healthz); also hosts Compose pins, stack docs, channels
freya-mcp Thin Streamable HTTP proxy over the same /v1 tools
freya-worker GPU facade — API proxies generate / assets / base-model
freya-operator Pins apiImage on FreyaStudio; does not live in this repo

Compat: treat as web/mcp ^0.1 require api ^0.1; api ^0.1 ↔ worker ^0.1 until the FOO-48 matrix lands in freya-web channels/.

/v1 surface (summary)

Public (no bearer when auth is configured still applies for these):

Method Path Role
GET /healthz, /v1/health Liveness
GET /v1/auth/status Auth mode
POST /v1/auth/login Admin / user login
GET /v1/auth/sso SSO handoff (ForwardAuth injects headers)

Protected when FREYA_API_TOKEN or admin password is set (Bearer / session / Basic):

Area Paths
Agent / media POST /v1/assist, /v1/chat, /v1/generate, /v1/series, /v1/run
Gallery GET/DELETE /v1/gallery…, remix / apply, community reproduction
Models & styles GET /v1/models, /v1/styles, /v1/route-defaults, /v1/base-models
Civitai search / lookup / images / media / models / install / jobs
Settings GET/PUT /v1/settings, /v1/studio, /v1/generation-meta…
Auth admin token rotate, me, logout, workspace (ETag / If-Match revision), admin users
Worker proxy `/v1/worker/stats
Metrics GET /v1/metrics/openrouter

Gallery image bytes and Civitai media proxy stay reachable without bearer so <img> tags work.

Quick start

cp .env.example .env   # set OPENROUTER_API_KEY for real LLM calls
cargo build --release
mkdir -p data/gallery
./target/release/freya-api --bind 127.0.0.1:8080
# curl -sS http://127.0.0.1:8080/healthz

Point a running freya-worker at FREYA_DIFFUSION_WORKER_URL (default in .env.example: http://127.0.0.1:8091).

Docker / Harbor

docker build -t freya-api:local .
docker run --rm -p 8080:8080 \
  -e OPENROUTER_API_KEY=… \
  -e FREYA_DIFFUSION_WORKER_URL=http://host.docker.internal:8091 \
  -v "$PWD/data/gallery:/data/gallery" \
  freya-api:local

Published image name: library/freya-api (Harbor). Operator / freya-web Compose pin the tag; this repo does not own cluster manifests.

Multi-replica sessions / rollout

Human SSO/admin sessions live in FREYA_USERS_DIR (default: beside FREYA_SECRETS_FILE) as sessions.json, coordinated with sessions.lock.

  • Replicas >1 need that directory on a shared RWX volume so every pod sees the same sessions and can take the file lock.

  • Rolling update: older builds write sessions.json without the lock / disk-merge path. Drain or stop old freya-api replicas before new pods mint or revoke sessions (scale to the new Revision / wait for old pods to terminate). Mixing old and new writers on the same file can drop peer-minted sessions and bounce Authentik users back to the login overlay.

  • Pre-cutover validation: this build fails closed on a malformed sessions.json (startup and auth refuse to treat decode errors as an empty map). Before bringing new replicas online, from a shell with the shared volume mounted:

    # must match UserStore/SessionRecord: map-shaped sessions; string username/role/createdAt;
    # displayName optional but must be a string when present (serde camelCase).
    python3 -c '
    import json,sys
    d=json.load(open(sys.argv[1]))
    assert isinstance(d, dict), "root must be object"
    s=d.get("sessions", {})
    assert isinstance(s, dict), "sessions must be object/map"
    for k,v in s.items():
      assert isinstance(v, dict), f"session {k} must be object"
      for f in ("username","role","createdAt"):
        assert isinstance(v.get(f), str) and v.get(f), f"session {k} missing string {f}"
      if "displayName" in v:
        assert isinstance(v.get("displayName"), str), f"session {k} displayName must be string"
    print("ok")
    ' "$FREYA_USERS_DIR/sessions.json"

    If decode fails (truncated write from a killed legacy pod), quarantine then continue with an empty map so pods can start; users re-auth via Authentik:

    mv "$FREYA_USERS_DIR/sessions.json" "$FREYA_USERS_DIR/sessions.json.bad.$(date +%s)"
    rm -f "$FREYA_USERS_DIR/sessions.dirsync.pending"
    # optional: echo '{"sessions":{}}' > "$FREYA_USERS_DIR/sessions.json"

    An interrupted rename leaves sessions.dirsync.pending on the shared volume; new pods re-persist under flock at startup until parent-dir sync succeeds.

  • After cutover: Authentik → Studio (or guidelines), not login; freya.apiToken stays s_…; GET /v1/auth/me returns 200.

Layout

Path Purpose
src/ Rust Studio API
packs/ Instruction packs + auto-models.json (FREYA_PACKS_DIR)
Dockerfile Harbor image (ffmpeg + binary + packs)
docs/hero.jpg Brand-first README hero

Guidelines

Freya is a tool: you supply keys and hardware, and you are liable for prompts and outputs. Third-party terms (OpenRouter, Civitai, Hugging Face, model licenses) still apply.

License

Apache License 2.0 — see LICENSE.

About

Freya Studio API — HTTP /v1 backend and packs for Freya

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages