* feat(scheduler): lifecycle rules, goal/limit parity and coded errors for scheduled tasks
- Migration 0031: nullable scheduled_tasks.unmet_streak_after_seq (internal
streak boundary) and stop_condition (the user's stop rule, own column).
- Stop rule is normalized (stop_rule.py) and appended only at launch; the
stored prompt never contains it. Wording adapts when scheduler.tool_enabled
is off.
- Willem 1: page-created tasks get goal evaluation, <standing_notes>, the
previous-run reference and own-schedule stop; request_stop and the
scheduled capability no longer require an origin conversation.
- Repository: single reactivation choke point raising
ScheduledTaskLimitsExhausted; streak boundary moves on goal/prompt/stop
condition/note changes (not on resume); goal-check failures neither count
nor reset the streak; pause of a finished task returns "finished"; trials
on a paused task keep the host pause marker.
- New repository reads: automatic_runs_used_for, active_run_status_for,
list_manageable_from_thread, thread_relation/thread_run on thread tasks,
task_ids_for_thread, run_number, and run_number/total_tokens/summary on
run history rows.
- REST: goal/max_runs/end_at/stop_condition on create and PATCH (null
clears, naive end_at = task timezone), resume recomputes from now with an
optional renewal body, once_time_passed, task_finished, limits_exhausted,
scheduler_not_running on create, trigger returns outcome/existing/thread_id,
task responses add automatic_runs_used and active_run_status.
- Coded errors {code, message, params} for routes, shared validation and the
chat capability (scheduled_task_errors.py), pinned by
contracts/scheduled_task_errors_contract.json; goal notes contract v2 with
check_failure_codes, scheduled_origin_key and host_run_errors (host_notes.py).
- /api/features adds scheduled_tasks {available, running, tool_enabled,
min_interval_seconds}; ScheduledTaskService.is_running.
- Docs: six README scheduler sections, API.md scheduled tasks section
(breaking error shape), CONFIGURATION.md, AGENTS notes, CHANGELOGs.
- Tests: migration 0031, stop rule, error contract, run listing, lifecycle
over HTTP, repository, service and capability cases; updated tests for the
new error shape, finished-task pause and head revision.
* feat(scheduler): conversation update/resume, run-conversation authority and readable launches
- schedule_task: update and resume actions, stop_condition and clear_fields
parameters, plain parameter types (value rules come back as coded results),
rewritten docstrings for schedule_task and stop_scheduled_task.
- Capability: update/resume share the REST validation and error codes;
interactive turns in a task's run conversation may manage that task;
scheduled runs keep only own-stop; grants require a running scheduler.
- Results: compact JSON-safe task views with local times, display card/text,
last run in list, timezone_source/browser_timezone, now_local; no ISO, user,
lease or origin fields; stop_instructions removed.
- Timezone: explicit > browser (context.client_timezone, validated in
start_run and never forwarded to the run config) > not needed for intervals
and offset run_at > timezone_required.
- Trial gate accepts natural direct requests after acknowledgements and
particles; trial results report thread_id and existing.
- Scheduled launches: stable message id scheduled-<task_run_id>, server-owned
deerflow_scheduled_origin metadata with the user-language parts, run thread
title for fresh-thread tasks.
- Worker records goal continuations in the verdict; lead prompt language rule
covers stored task text and scheduled runs.
- Docs: six READMEs, CONFIGURATION, API, runtime/tools AGENTS, CHANGELOGs.
* feat(frontend): scheduled-task core types, formatting, errors and glossary
- throwGatewayApiError now throws GatewayApiError (status, code, params,
rawMessage); message stays the string detail or detail.message
- scheduled-task types gain stop_condition, automatic_runs_used,
active_run_status, origin/notes, run_number/total_tokens/summary, thread
relation, trigger result, renewal and scheduled origin; isTaskBusy and
hasActiveRun helpers
- api: fetchScheduledTask, resume with optional renewal body, typed trigger
result and update payload with null clears
- hooks: polling at 3 s while a run is active (list, thread list, run
history), useScheduledTask with live gating and final 404, useInView,
localized error toasts; run history refreshes tasks when a run finishes
- new pure modules: errors.ts (contract code to localized copy), format.ts
(relative task times, viewer time, display zone), status.ts, actions.ts,
run-error.ts; describeTaskSchedule in cron.ts; goal-outcome adds unchecked
goal checks, describeTaskOutcome and parseStopRunId
- features: scheduled_tasks block with defaults when missing
- buildRunContext sends client_timezone
- titleOfThread takes a localized untitled label; breadcrumb names scheduled
tasks and agents; reference chips use the localized untitled label
- schedule input: shared browserTimeZone, labelled selects, aria-pressed
type toggles, interval minimum from the hint template
- i18n: all PR1 scheduled-task keys in en-US and zh-CN, glossary fixes,
recipe instructions moved into i18n
- e2e mocks follow the new task, trigger, resume, thread-task and features
shapes; expectNoRawIdentifiers helpers for e2e and DOM tests
- tests for errors, format, cron, status, actions, goal outcome, run errors,
hooks, run context, thread titles and features; scheduled e2e copy updated
* feat(frontend): list-first scheduled tasks page with outcomes and editable goals
- page.tsx is now a thin composition of components/workspace/scheduled-tasks:
status tabs (All/Active/Paused/Finished) and search over the task list,
?task_id= deep link with router.replace on selection, ?thread_id= chip
with Show all, empty state, scheduler-off notice and unavailable state
- task list rows show the schedule in words and one status line (next run,
running now, paused by agent, auto-paused, finished by its cap)
- task detail: status badge, actions from availableActions with reasons,
More actions menu (Duplicate, Copy task ID, Delete), outcome notice,
Runs / Stops when / Each run's goal / Does / Notes from chat / History,
origin chat link; success toasts for every action
- run rows: run number or Trial run, summary, goal and assumption badges,
continuations, tokens, Open chat link; raw errors and the evaluator
reason only behind Details
- create/edit/duplicate dialog with goal, stop condition, safety caps and
advanced agent/context options; PATCH sends only changed fields, null
clears a cap
- renew dialog raises or removes caps and resumes in one request; a
limits_exhausted Resume opens it
- removed i18n keys the old page used; added feedback.resumedNoTime
- recorded en-3 and zh-1 page fixtures; scheduled e2e specs rewritten for
the new page; DOM tests for the detail and the form dialog
- CHANGELOG entries and the frontend AGENTS.md scheduled-task note
* feat(frontend): live schedule card, run conversation provenance and header entry
- schedule_task results (create, update, pause, resume, trial, delete) become
an assistant:scheduled-task message group rendered as a live card: schedule,
next run, stop condition with the safety cap, goal, where results go, Run
once now, Pause/Resume and Open task; the card polls the task only while it
is on screen and shows deleted, scheduler-off and limits-exhausted states
- one card per task per assistant turn; the card group is not a turn boundary
for usage, branching, editing, outline or skill attribution
- a human message with deerflow_scheduled_origin stays a human group with
scheduledOrigin and renders as a "Scheduled run / Trial run" block with the
task instructions, stop condition and notes collapsed; the launched text is
never shown and the message is not editable
- readable step labels for schedule_task actions and stop_scheduled_task
- ThreadScheduledTasksButton replaces the header link: hidden without tasks,
shows the count, links to the task (or the chat filter), and a run's chat
links to its task
- recorded en-3 / zh-1 chat and run-thread fixtures; chat-card and run-thread
e2e specs; unit and DOM tests for parsing, grouping, turn boundaries, card,
run block, header button, step labels and reconnect hydration
- i18n: header.countLabelOne added, unused card.next removed; CHANGELOG and
frontend AGENTS.md notes
* fix(scheduler): address verification findings
Move the scheduled-task lifecycle guidance from backend/AGENTS.md into the persistence guide and leave a one-line pointer, so the effective AGENTS.md chains for agents/middlewares, sandbox and subagents stay under the 98304-byte hard limit enforced by scripts/check_agent_guidance.py in lint-check.
* fix(scheduler): address review findings
* fix(scheduled-tasks): polish from live acceptance
- zh schedule wording: an interval of one unit reads 每分钟 / 每小时 / 每秒,
and a saved interval of whole days reads 每天 / 每 2 天 (Every day / Every 2
days) instead of 每 1 分钟 or 每 24 小时; several units keep the number
- zh spacing: 已于{time} 满足 and 在{time} 的运行中 now leave a space between
the interpolated time and the Chinese after it; a copy test guards every
scheduled-task zh string against a placeholder glued to Chinese
- run summary: when the first line of the final reply only leads in to a list
(ends with ":" or ":"), the list items follow it as plain text (bullets,
numbering, checkboxes, bold, code and links stripped), joined with ";" for
CJK text and "; " otherwise, within the 160-character cap
- a schedule_task result (create, update, pause, resume, trial, delete) that
arrives in a chat invalidates that chat's task list, the tasks list and the
named task, so the header button and cards update without waiting for the
idle poll; results already in the loaded history do not refetch
- e2e and unit fixtures are now the live acceptance recordings (DeepSeek
Flash, demo data, fictional names): live-weekday.json (create, trial, edit,
pause, resume in one zh chat) and live-minute.json (per-minute chat, run 1
and run 2, paused by the agent), fetched with GET from the demo Gateway and
trimmed; the hand-shaped en-3 / zh-1 fixtures are removed and the chat-card,
run-thread and tasks-page specs run in both locales over the recorded data
* docs(changelog): reference #6378 for the scheduled-tasks entries
* docs(agents): shorten the scheduled-task pointer to stay under the guidance limit
* test(scheduled-tasks): pin the live takes to their recorded time zone
The live fixtures were recorded in Asia/Shanghai, and an interval task
reads in the viewer's zone, so the 16:48 assertions failed on UTC CI
runners. Pin the browser zone in the two live-take e2e specs and the
zh live-take unit test.
* fix(scheduled-tasks): keep untouched end times and drop a chat filter the new task is not in
- The edit, duplicate and renew dialogs keep a stored end time's instant
while its field still shows it. A minute-precision wall value cannot
keep seconds or name the later 01:30 of a DST fall-back, so a
title-only edit moved the cap an hour earlier, and raising the run
limit re-sent the end time without its seconds.
- Creating or duplicating a task from a chat's task view drops the chat
filter when the new task does not belong to that chat, instead of
showing "This task isn't one of this chat's tasks".
* fix(scheduled-tasks): tie pause notices to the pause they describe
- Paused by agent links and times only the run named in last_error. When
that run is not loaded, the notice shows no link and the task's own time
instead of an earlier run that also asked to stop.
- The outcome notice reads the latest history page whichever page is
shown, so browsing older runs no longer swaps the auto-pause reason and
"Open latest run" to an earlier miss. It shares that page's request.
* fix(scheduled-tasks): three lifecycle gaps found while re-checking review classes
- The edit form compares a cron in the form its schedule input emits, so an
untouched "0 09 * * 0,6" is not re-sent as "0 9 * * 6,0" and a title-only
edit no longer re-arms or refuses a finished task.
- Chat resume asks for a timezone, as update does, when a naive end_at would
land in the UTC placeholder of a zone-free task.
- Re-arming a task clears a host pause marker, as resume does, so a later
manual pause no longer reads as "Paused by agent".
* fix(scheduled-tasks): keep the notice's latest-runs query from refreshing older pages
useLatestScheduledTaskRuns kept React Query's default refetch on mount,
focus and reconnect, so going offline and back while an older history page
was shown fetched the latest page again. Refreshing stays with the history,
which refreshes the latest page only while it is shown.
* test(scheduled-tasks): let the viewer's time carry its own day label
Between 16:00 and 24:00 UTC, UTC and Asia/Shanghai are on different days,
so the run prompt shows "Tomorrow 01:00 · Today 09:00 your time" and the
fixed "01:00 · 09:00 your time" assertion failed depending on the hour.
---------
Co-authored-by: Totoro-qaq <279883115+Totoro-qaq@users.noreply.github.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
69 KiB
API Reference
This document provides a complete reference for the DeerFlow backend APIs.
Overview
DeerFlow backend exposes two sets of APIs:
- LangGraph-compatible API - Agent interactions, threads, and streaming (
/api/langgraph/*) - Gateway API - Models, MCP, skills, uploads, and artifacts (
/api/*)
All APIs are accessed through the Nginx reverse proxy at port 2026.
For agent conversations, clients can either pre-create a thread
(POST /api/langgraph/threads) or start immediately with the stateless stream
endpoint (POST /api/langgraph/runs/stream). The latter auto-creates a thread
and returns thread_id and run_id in the response Content-Location header.
Authentication
Browser sessions authenticate with the access_token session cookie issued at
login. Programmatic clients can instead use a personal access token (PAT)
sent as a Bearer credential:
POST /api/threads/search
Authorization: Bearer dfp_...
Content-Type: application/json
{}
PATs require a configured database backend (SQLite/PostgreSQL) — on the
memory-only backend, Bearer credentials are rejected and PAT management routes
return 503.
Account Preferences
GET /api/v1/auth/preferences returns the signed-in browser user's four
preferences. PATCH updates only explicitly supplied fields and returns 204.
Both require X-Expected-User-Id matching the session user; PATCH also requires
the normal X-CSRF-Token header. The expected ID is a stale-tab guard, not an
authorization credential. PAT, internal, and auth-disabled callers receive
403; a different session user receives 409.
{
"notification_enabled": false,
"model_name": "my-model",
"mode": "pro",
"reasoning_effort": "high"
}
All four fields accept null to restore the default. mode accepts flash,
thinking, pro, or ultra; reasoning_effort accepts minimal, low,
medium, or high; model names are at most 200 characters. Unknown fields and
invalid values return 422. Missing preferences read as null. Separate-field
patches preserve each other's changes, and same-field writes are last-commit-wins.
Storage requires SQLite or PostgreSQL (503 when unavailable). Browser
notification permission remains device-local and is not changed by this API.
Personal Access Tokens
Base URL: /api/v1/auth
PAT management requires an interactive session (a PAT cannot manage PATs or change passwords, so a leaked automation token cannot mint fresh credentials). The raw token is returned exactly once at creation; only its SHA-256 digest is stored server-side.
Create Token
POST /api/v1/auth/pats
Content-Type: application/json
Request Body:
{
"name": "ci-runner",
"scopes": ["threads:read", "runs:create", "runs:read"],
"expires_in_days": 90
}
scopes— subset of the route permissions:threads:read,threads:write,threads:delete,runs:create,runs:read,runs:cancel. A PAT can only narrow its owning user's permissions, never widen them.expires_in_days— optional (1–365); omitted means the token never expires.
Response (201):
{
"id": "0f0c6e6a-...",
"name": "ci-runner",
"scopes": ["runs:create", "runs:read", "threads:read"],
"expires_at": "2026-11-25T10:30:00Z",
"created_at": "2026-08-27T10:30:00Z",
"token": "dfp_..."
}
Save token immediately — it cannot be retrieved again.
List Tokens
GET /api/v1/auth/pats
Returns the caller's tokens with last_used_at / revoked_at audit fields;
never returns digests or raw tokens.
Revoke Token
DELETE /api/v1/auth/pats/{pat_id}
Revocation is immediate.
PAT Constraints
- A request carrying an
Authorizationheader that fails validation gets a hard401— it never falls back to the session cookie. - Cancel capability requires
runs:cancelon every request dimension that carries it, not just the dedicated cancel route:?action=interrupt|rollbackonPOST /api/threads/{thread_id}/runs/{run_id}/stream(action-less joins stay atruns:read), andmultitask_strategy=interrupt|rollbackon run creation (the defaultrejectstays atruns:create). Joining a run's stream is pure observation — an observer disconnecting never cancels the run. - Route-level default-deny: PAT requests are admitted only to the
thread/run lifecycle routes the v1 scopes govern —
POST /api/threads(create),POST /api/threads/search(list),GET/PATCH/DELETE /api/threads/{thread_id}, the threadgoal/state/compact/history/branchessubroutes, and exactly the implemented/runssubroutes (GET|POST /api/threads/{thread_id}/runs, the POST-onlystream,wait,regenerate/prepare, andedit-regenerate/preparecollection endpoints,GET /api/threads/{thread_id}/runs/{run_id}plus itscancel(POST),join/messages/events/workspace-changes(GET), andGET|POST .../runs/{run_id}/stream), plusPOST /api/runs/stream|waitandGET /api/runs/{run_id}/messages|feedback. A route added under/runsis denied until explicitly added to the policy. Every other authenticated route — memory, agents, models, MCP/skills config, integrations, channels, uploads — answers403to PAT callers regardless of scopes. Scope enforcement alone only constrains permission-decorated routes, so the allowlist is the outer boundary; session-cookie callers are unaffected. - PAT credentials never carry admin capability, even when the owning user is an admin. This includes extension-contributed admin routes: the extension principal projection suppresses every admin signal for PAT callers.
- Revoking or deleting the owning user invalidates their PATs on the next request.
LangGraph-compatible API
Base URL: /api/langgraph
The public LangGraph-compatible API follows LangGraph SDK conventions. In the unified nginx deployment, Gateway owns /api/langgraph/* and translates those paths to its native /api/* run, thread, and streaming routers.
Threads
Create Thread
POST /api/langgraph/threads
Content-Type: application/json
Request Body:
{
"metadata": {}
}
Response:
{
"thread_id": "abc123",
"created_at": "2024-01-15T10:30:00Z",
"metadata": {}
}
Get Thread State
GET /api/langgraph/threads/{thread_id}/state
Response:
{
"values": {
"messages": [...],
"sandbox": {...},
"artifacts": [...],
"thread_data": {...},
"title": "Conversation Title"
},
"next": [],
"config": {...}
}
Runs
Create Run
Execute the agent with input.
POST /api/langgraph/threads/{thread_id}/runs
Content-Type: application/json
Idempotency-Key: <unique key for this logical request> # optional
The thread-scoped create, stream, and wait endpoints accept an optional
Idempotency-Key header. Retrying with the same authenticated user, thread_id,
and key reuses the existing run instead of executing the input again. The key is
shared across /runs, /runs/stream, and /runs/wait for a given user and
thread, so the same key string cannot back two different calls even across those
endpoints. Reuse is bound to the original input, assistant_id and
conversation_references; a retry that changes them returns 409. Generate a new key for every intentional user
action; reuse a key only when retrying that same action after an uncertain HTTP
result. Keys may be at most 255 characters. Stateless /api/langgraph/runs/*
endpoints do not support this header because requests without an explicit thread
create a new temporary conversation.
Retrying a still-running run that this worker cannot stream returns 409 from
/runs/stream (Run ... is not active on this worker and cannot be streamed)
with no Retry-After. The same shape on /runs/wait returns 200
{"status": "<durable status>", "error": ...} without blocking for a final
state. Retrying a finished run through /runs/wait also returns that durable
status payload rather than the latest thread checkpoint: a later run on the
same thread may have advanced the head, and /wait does not claim that head
as this run's result. That status is the durable row after completion, not
the hydrated record from admission time. The original creating /wait still
returns this run's checkpoint even if a retry overlaps while it is waiting. Retrying a finished run whose SSE log is gone emits a gap frame
(stream_replay_gap, recovery: reload_durable_state) on the creating
/runs/stream endpoint and closes without an end frame; reload durable
thread/run state instead of treating the stream as empty. Observer joins of
that same run still end with end. Stateless /api/langgraph/runs/stream
does not accept this header and keeps the existing missing-stream close of
end; the gap signal is only on a thread-scoped creating retry.
Request Body:
{
"input": {
"messages": [
{
"role": "user",
"content": "Hello, can you help me?"
}
]
},
"config": {
"recursion_limit": 100,
"configurable": {
"model_name": "gpt-4",
"thinking_enabled": false,
"is_plan_mode": false
}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}
Stream Mode Compatibility:
- Use:
values,messages-tuple,custom,updates,debug,tasks,checkpoints - Unsupported modes, including
messages,events, andtools, return422before a run is created. DeerFlow never substitutesvaluesfor an unsupported mode.
Run Option Compatibility:
- Supported concurrency strategies:
reject,rollback, andinterrupt - Compatibility default:
if_not_exists="create"; this matches DeerFlow's current behavior - Artifact delivery is enforced automatically when a run creates or modifies regular files under
/mnt/user-data/outputs.present_filesmust present at least one path produced by the current run (or a directory containing it), and the terminal receipt must be persisted; presenting only an unrelated file does not satisfy delivery. Runs without changed outputs retain ordinary conversational behavior.artifact_deliveryis not a client-settable run option. - Unsupported options return
422:webhook,stream_resumable=true,after_seconds,feedback_keys, any non-nullon_completionvalue (including the SDK values"complete"and"continue"),if_not_exists="reject", andmultitask_strategy="enqueue" stream_resumable=falseis accepted: it is the LangGraph SDK's default and requests the non-resumable stream DeerFlow already serves- Undeclared SDK options, including
checkpoint_duringanddurability, also return422instead of being silently discarded
When outputs changed during the run, run.delivery events retain the Slice 1
facts (presented, paths, and by_tool) and add produced_paths,
presented_paths, matched_paths, plus an explicit verdict: verification,
stage (presented, mismatched, or not_started), and satisfied. Receipts
for runs without changed outputs keep their existing shape.
Recursion Limit:
config.recursion_limit caps the number of graph steps LangGraph will execute
in a single run. The unified Gateway path uses the top-level recursion_limit
from config.yaml (default 100) when a request does not provide one. Clients
can still set recursion_limit explicitly in the request body, and a valid
request value takes precedence. Scheduled-task launches do not take a client body: they
use scheduler.recursion_limit from config.yaml (default 1000, matching
the web UI). For safety, the Gateway clamps any supplied
or configured value to a server ceiling (max_recursion_limit in config.yaml,
default 1000) so a single run cannot execute unbounded graph steps (runaway
LLM cost / DoS); invalid or non-positive request values fall back to the
configured default. Both top-level fields are read per run, so edits apply to
the next request without restarting the Gateway. This top-level setting applies
to Gateway API runs only; IM channel and embedded DeerFlowClient runs retain
their own defaults and override paths.
Configurable Options:
model_name(string): Override the default modelthinking_enabled(boolean): Enable extended thinking for supported modelsis_plan_mode(boolean): Enable TodoList middleware for task tracking
Response: Server-Sent Events (SSE) stream
event: values
data: {"messages": [...], "title": "..."}
event: messages
data: {"content": "Hello! I'd be happy to help.", "role": "assistant"}
event: end
data: {}
Referencing a previous conversation
With read_conversation enabled in config.yaml (see configuration),
Gateway API callers can attach up to three explicit references to create/stream/wait requests:
{
"input": {"messages": [{"role": "user", "content": "Use the requirements agreed in the referenced conversation."}]},
"conversation_references": ["https://deerflow.example/workspace/chats/source-thread"]
}
A reference is a valid thread ID or an absolute /workspace/chats/{thread_id} URL
(also /workspace/agents/{agent_name}/chats/{thread_id} for custom agents)
with the same scheme and authority as the run request, without query or fragment.
URLs are parsed as local selectors and are never fetched. For split-origin clients
or internal proxies, pass the thread ID. The field is separate from message text:
links in pasted documents, tool results, or previous messages grant no access.
The server supplies source IDs to the model as background user-role data and
binds the reader to this run's references and authenticated identity.
Clients that cannot add top-level fields to a run request (the LangGraph JS SDK
builds a fixed body and drops unknown keys) may send the same list as
context.conversation_references:
{
"input": {"messages": [{"role": "user", "content": "Use the requirements agreed in the referenced conversation."}]},
"context": {"conversation_references": ["https://deerflow.example/workspace/chats/source-thread"]}
}
The Gateway lifts the key out of context before the run context is assembled,
so it has the same bounds and error locations as the top-level field, is
recorded on the run in the same way, and never reaches the merged run context
or the checkpointed configurable. Sending the top-level field and the context
key together returns 422. GET /api/features reports
conversation_references.enabled (the tool is configured) and max_references,
so a client can hide its entry point on deployments without the tool.
The request requires runs:read as well as the normal run-creation permission.
The tool rechecks source ownership on each read; foreign, deleted and unowned
legacy threads are unavailable. read_conversation(thread_id, cursor?, limit?)
reads newest-first pages (messages within each page are chronological), at most
50 visible user/assistant messages, 4,000 characters per message and 20,000 text
characters per page. Each page also stays within the tool-output budget that
applies to read_conversation (tool_output.tool_overrides.read_conversation,
else externalize_min_chars, and fallback_max_chars; 12,000 serialized
characters by default), so results reach the model inline instead of being
externalized to a file. A message that does not fit starts the next page intact.
Only a message longer than 4,000 characters, or one whose serialized form alone
exceeds the budget, is truncated. Such a message carries
continuation: {"message_seq", "offset"}; read_conversation(thread_id, message_seq=..., offset=...) without a cursor returns the next part of that one
message (at most 20,000 text characters, sized to the same budget) with its
offset, text_length and, while text remains, a new continuation. Offsets
refer to the source's current text: an offset past its end returns
invalid_request, and a message that is no longer visible is unavailable. If the
read_conversation budget is too small to return any text (below roughly 800
serialized characters), the result is output_budget_too_small rather than a
continuation that makes no progress.
Results include message IDs, sequence numbers, continuation, truncation and
unavailability. Hidden messages, reasoning blocks, raw tool
results and subagent internals are excluded. Source data is not changed.
Live reads and retained copies. Each call reads the source's current visible history. Editing or regenerating the source can change subsequent reads, including later pages; a reference does not pin an immutable transcript. Text already returned to the destination is a copy and is not automatically refreshed by source changes.
Read permission lasts only for this run, including its internal continuation steps. Every new run, including resume, regenerate or edit replay, must submit references again; checkpoints and old hints never restore permission. A resume can reuse IDs already visible in the interrupted conversation, but needs the explicit request field again. Missing/expired transcripts are not reconstructed from checkpoints or memory.
Permission expiry does not erase excerpts already stored in the destination conversation or conclusions derived from them. Deleting the source does not retroactively erase those copies either; they follow the destination's own retention and deletion behavior. Once the source is unavailable, further source reads report unavailability rather than reconstructing it from destination copies.
Incomplete requirements. When truncated is true, the tool's notice tells
the agent to read the rest through each cut message's continuation before relying
on it, and to acknowledge the omission and request the missing material if that
read is unavailable. has_more: false means there are no older messages to page
through, not that every returned message is complete. This is model guidance, not
a new confirmation mechanism or a guarantee of model compliance.
This first version adds no frontend picker or link-to-reference conversion. The tool is unavailable to bootstrap agents, subagents and embedded clients without a host-provided reader. Active tool/skill policies continue to apply.
Get Run History
GET /api/langgraph/threads/{thread_id}/runs
Response:
{
"runs": [
{
"run_id": "run123",
"status": "success",
"created_at": "2024-01-15T10:30:00Z"
}
]
}
Stream Run
Stream responses in real-time.
POST /api/langgraph/threads/{thread_id}/runs/stream
Content-Type: application/json
Idempotency-Key: <unique key for this logical request> # optional
Same request body as Create Run. Returns SSE stream.
Stateless Stream Run
Start a conversation without creating a thread first. Gateway auto-creates a
thread when config.configurable.thread_id is omitted, and returns both
identifiers in the response Content-Location header.
POST /api/langgraph/runs/stream
Content-Type: application/json
Accept: text/event-stream
Through Nginx, /api/langgraph/runs/stream is rewritten to the native Gateway
path POST /api/runs/stream.
Request Body: Same as Create Run. Omit thread_id to start a
new conversation; include it to continue an existing one:
{
"input": {
"messages": [
{
"role": "user",
"content": "Hello, can you help me?"
}
]
},
"config": {
"recursion_limit": 100,
"configurable": {
"model_name": "gpt-4",
"thinking_enabled": false,
"is_plan_mode": false
}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}
Response: Server-Sent Events (SSE) stream with a Content-Location header:
Content-Location: /api/threads/{thread_id}/runs/{run_id}
Clients should parse thread_id and run_id from this header (the path ends
with /runs/{run_id}). Persist thread_id and send it back on the next turn
via config.configurable.thread_id to keep conversation history.
Continuing a conversation:
{
"input": {
"messages": [
{
"role": "user",
"content": "What did I just ask?"
}
]
},
"config": {
"configurable": {
"thread_id": "abc123",
"model_name": "gpt-4"
}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}
Gateway API
Base URL: /api
Custom Agent portability
GET /api/agents/{name}/export downloads a version-1 JSON package for a
caller-owned Custom Agent. The package uses format: "deerflow.custom-agent"
and contains the portable Agent configuration plus SOUL. It excludes memory
contents, conversations, credentials, and deployment-owned GitHub bindings.
POST /api/agents/import creates the packaged Agent for the current user.
Pass ?name=<new-name> to choose a different local identifier. The document
schema rejects unknown fields and unsupported format/version values; invalid
names or models return 422, and an existing name returns 409 without changing
the existing Agent. Import is create-only and never restores runtime state.
{
"format": "deerflow.custom-agent",
"version": 1,
"agent": {
"name": "research-lead",
"description": "Coordinates parallel research",
"model": "deepseek-v3",
"tool_groups": ["web"],
"skills": ["literature-review"],
"allowed_subagents": ["researcher", "reporter"],
"memory_enabled": true,
"soul": "Delegate independent searches, then synthesize evidence."
}
}
Models
List Models
Get all available LLM models from configuration.
GET /api/models
Response:
{
"models": [
{
"name": "gpt-4",
"display_name": "GPT-4",
"supports_thinking": false,
"supports_reasoning_effort": false,
"reasoning": {"thinking": "unsupported", "effort": null, "history": null, "source": "legacy"}
},
{
"name": "deepseek-v3",
"display_name": "DeepSeek V3",
"supports_thinking": true,
"supports_reasoning_effort": true,
"reasoning": {
"thinking": "optional",
"effort": {"values": ["minimal", "low", "medium", "high"], "default": null, "aliases": {}},
"history": null,
"source": "legacy"
}
},
{
"name": "glm-5.3-flash",
"display_name": "GLM-5.3-Flash",
"supports_thinking": true,
"supports_reasoning_effort": true,
"reasoning": {
"thinking": "required",
"effort": {"values": ["low", "high", "max"], "default": "high", "aliases": {"minimal": "low", "medium": "high"}},
"history": "clear",
"source": "contract"
}
}
]
}
supports_thinking and supports_reasoning_effort are deprecated projections of
reasoning. reasoning.source is legacy when the profile declares no
reasoning: block (the booleans were normalized) and contract when it does.
Get Model Details
GET /api/models/{model_name}
Response:
{
"name": "gpt-4",
"display_name": "GPT-4",
"model": "gpt-4",
"max_tokens": 4096,
"supports_thinking": false,
"supports_reasoning_effort": false,
"reasoning": {"thinking": "unsupported", "effort": null, "history": null, "source": "legacy"}
}
MCP Configuration
Get MCP Config
Get current MCP server configurations.
GET /api/mcp/config
Requires an authenticated admin session. Sensitive env/header/OAuth secret
values are masked in the response. Environment placeholders outside secret
containers are returned in their raw form so editing cannot expose or persist
their expanded values. Invalid operator-authored JSON/config shapes return
400 instead of being reported as a Gateway fault.
Response:
{
"mcp_servers": {
"github": {
"enabled": true,
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "***"
},
"description": "GitHub operations"
}
}
}
Update MCP Config
Update MCP server configurations.
PUT /api/mcp/config
Content-Type: application/json
Requires an authenticated admin session. API-managed stdio MCP servers may
only use allowed executable names for command (default: npx, uvx). Set
DEER_FLOW_MCP_STDIO_COMMAND_ALLOWLIST to a comma-separated list when a
deployment needs additional trusted launchers.
Request Body:
{
"mcp_servers": {
"github": {
"enabled": true,
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "$GITHUB_TOKEN"
},
"description": "GitHub operations"
}
}
}
Response:
{
"mcp_servers": {
"github": {
"enabled": true,
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "***"
},
"description": "GitHub operations"
}
}
}
Update One MCP Server State
Enable or disable one configured MCP server without replacing the full extensions configuration.
PATCH /api/mcp/config
Content-Type: application/json
Requires an authenticated admin session. Enabling a stdio server validates
that server's command against the same allowlist used by the full PUT
endpoint. Disabling a server does not require its command to be allowlisted, and
invalid commands on other servers do not block the update. The endpoint
preserves secrets, environment-variable placeholders, skills, custom server
fields, and other top-level extensions config. SSE/HTTP targets may use either
DeerFlow's type field or the MCP-spec transport field.
Request Body:
{
"server_name": "semantic-scholar",
"enabled": false
}
The response is the full masked MCP configuration, matching GET and PUT.
An unknown server_name returns 404; attempting to enable a server with a
disallowed stdio command returns 400.
Add MCP Servers
Add one or more servers without replacing existing entries. The Gateway
re-reads the file under the shared configuration lock, so concurrent sibling
changes are preserved. Existing names return 409.
POST /api/mcp/config/servers
Content-Type: application/json
The request body uses the same mcp_servers map as the full PUT endpoint.
Replace One MCP Server
Completely replace one existing server while preserving sibling entries.
Omitted ordinary fields are deleted or reset; explicit *** placeholders
restore the corresponding stored secret.
A disabled stdio replacement may keep a syntactically valid command outside
the allowlist for offline editing. Command-shape and code-injecting environment
variable checks still run when saving; the allowlist and executable-argument
policy run when the server is enabled.
PUT /api/mcp/config/server
Content-Type: application/json
{
"server_name": "github",
"server": {
"enabled": true,
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {"GITHUB_TOKEN": "***"}
}
}
Delete One MCP Server
Delete one server without replacing sibling entries. The server name is a path parameter and the DELETE request has no body. Percent-encode names before placing them in the URL; the path converter also keeps legacy empty and slash-containing names addressable.
DELETE /api/mcp/config/servers/{server_name}
All targeted mutations return the full masked MCP configuration. Before any write, the Gateway resolves environment variables in a copy and validates the same expanded document the runtime will load while persisting the original raw placeholders.
Reset MCP Tools Cache
Publish a shared cache generation, then clear cached MCP tools and persistent
MCP sessions in the handling process. Every Gateway worker sharing the writable
extensions-config directory observes that generation and reloads tools on its
next agent run or tool lookup. This also refreshes remote tools/list changes
that did not modify extensions_config.json.
POST /api/mcp/cache/reset
Requires an authenticated admin session.
Response:
{
"success": true,
"scope": "shared_config",
"message": "MCP tools cache reset published through the shared config directory. Tools will reload on next use."
}
shared_config means every worker mounting that same directory observes the
generation; it does not claim a deployment-wide broadcast when replicas use
independent filesystems. When no extensions-config path can be resolved, the
request still resets the current worker and returns "scope": "process".
Skills
List Skills
Get all available skills.
GET /api/skills
Response:
{
"skills": [
{
"name": "pdf-processing",
"display_name": "PDF Processing",
"description": "Handle PDF documents efficiently",
"enabled": true,
"license": "MIT",
"path": "public/pdf-processing"
},
{
"name": "frontend-design",
"display_name": "Frontend Design",
"description": "Design and build frontend interfaces",
"enabled": false,
"license": "MIT",
"path": "public/frontend-design"
}
]
}
Get Skill Details
GET /api/skills/{skill_name}
Response:
{
"name": "pdf-processing",
"display_name": "PDF Processing",
"description": "Handle PDF documents efficiently",
"enabled": true,
"license": "MIT",
"path": "public/pdf-processing",
"allowed_tools": ["read_file", "write_file", "bash"],
"content": "# PDF Processing\n\nInstructions for the agent..."
}
Enable or Disable Skill
PUT /api/skills/{skill_name}
Content-Type: application/json
Requires an authenticated admin session.
Request Body:
{
"enabled": false
}
Response: the updated skill. An unknown skill_name returns 404.
{
"name": "pdf-processing",
"description": "Handle PDF documents efficiently",
"license": "MIT",
"category": "public",
"enabled": false,
"editable": false
}
Install Skill
Install a skill from a .skill file.
POST /api/skills/install
Content-Type: multipart/form-data
Request Body:
file: The.skillfile to install
Response:
{
"success": true,
"message": "Skill 'my-skill' installed successfully",
"skill": {
"name": "my-skill",
"display_name": "My Skill",
"path": "custom/my-skill"
}
}
Export a Custom Skill
Admin session authentication is required for both requests. PAT credentials cannot export. Only the current user's custom skill is eligible; public, legacy and integration fallback is never used. A disabled custom skill remains eligible.
GET /api/skills/custom/{skill_name}/export-manifestreturnsskill_name,revision(SHA-256 or null),can_export,file_count,directory_count,total_bytes,files(path,type,size,executable),requirements(compatibility,allowed_tools,required_secretsnames and optional flags), and structuredwarnings/blockers. Paths are relative;.is the package root, counted in directory/entry totals. Structural blockers return a non-downloadable manifest. Declarations are not credential values or dependency verification.GET /api/skills/custom/{skill_name}/export?expected_revision=<64 lowercase hex characters>recaptures content and rejects stale previews with 409 before sending ZIP headers. Successful responses carryapplication/zip, attachment<skill_name>.skill, accurateContent-Length,Cache-Control: private, no-store, andX-Content-Type-Options: nosniff.
Error detail contains a safe code, message, and optional relative path. Codes/statuses: skill_not_found 404, skill_changed 409, skill_export_limit_exceeded 413, skill_export_unsupported 422, skill_export_busy 429, skill_export_timeout 503, skill_export_failed 500; existing 401/403 auth behavior applies. Limits are 4096 entries including directories, 64 MiB/file, 100 MiB raw/ZIP, 1 MiB frontmatter, 1024 UTF-8 bytes per ZIP path and depth 32. Frontmatter preflight rejects YAML aliases and bounds structure to 32 nesting levels / 16384 parser events before constructing YAML objects. A 5-second lock wait and 60-second cooperative worker deadline bound work; blocking OS calls cannot be forcibly interrupted. Two export slots are shared across all users in each Gateway process; both previews and downloads use them, and 429 means that process-wide capacity is occupied. Slots remain held through worker drain and temporary-file cleanup. The streaming phase has a separate 120-second inactivity deadline, reset after each successful ASGI send. A continuously progressing transfer may exceed 120 seconds overall; a stalled send does not reset the deadline. Expiry aborts the incomplete download (no replacement JSON after ZIP headers); clients must retry. Client disconnect during preparation cancels and drains the worker, then exits the handler normally rather than leaking a synthetic task cancellation. No export cache, persistent job or sharing URL is created.
Raw skill files, sidecars and empty directories are preserved. No hooks/scripts run during export and no secrets are redacted from package files. Import still uses normal security scanning and conflict checks. Export requires no-follow descriptor-relative host filesystem operations; unsupported platforms receive 422 rather than following links unsafely.
Reload Skills
Invalidate the skill prompt caches for every user in the current Gateway process. Subsequent runs rescan the configured public, custom, and legacy skill directories; runs that have already started keep their existing skill snapshot.
POST /api/skills/reload
The request has no body and requires an authenticated administrator. For a cookie-authenticated request, send the CSRF cookie value in the matching header:
curl -X POST http://localhost:2026/api/skills/reload \
-b cookies.txt \
-H "X-CSRF-Token: <csrf_token-cookie-value>"
Response:
{
"success": true,
"scope": "process",
"message": "Skill caches invalidated; subsequent runs in this Gateway process will rescan the latest skills."
}
success confirms cache invalidation, not that every file on disk was valid:
malformed skills retain the existing parser behavior of being skipped and
logged. The endpoint returns 401 for unauthenticated callers, 403 for
non-admin users, and a generic 500 if the invalidation mechanism itself
fails or the process-local background scan does not finish within the cache
refresh timeout. A loader-level failure, such as an unavailable mounted root,
does not publish an empty catalog: the last successfully loaded process cache
remains available. A timed-out scan continues in its daemon worker and can
still populate the process cache when it finishes.
The scope is deliberately process-local. Each Uvicorn worker or Kubernetes Pod must be called directly; repeated requests through a load-balanced Service do not guarantee that every instance is reached. External MinIO/NFS/CSI writes bypass the validation, SkillScan, and history used by the install/edit APIs, so the mounted directory must be writable only by trusted operators.
File Uploads
Upload Files
Upload one or more files to a thread.
POST /api/threads/{thread_id}/uploads
Content-Type: multipart/form-data
Request Body:
files: One or more files to upload
Response:
{
"success": true,
"files": [
{
"filename": "document.pdf",
"size": 1234567,
"path": ".deer-flow/threads/abc123/user-data/uploads/document.pdf",
"virtual_path": "/mnt/user-data/uploads/document.pdf",
"artifact_url": "/api/threads/abc123/artifacts/mnt/user-data/uploads/document.pdf",
"markdown_file": "document.md",
"markdown_path": ".deer-flow/threads/abc123/user-data/uploads/document.md",
"markdown_virtual_path": "/mnt/user-data/uploads/document.md",
"markdown_artifact_url": "/api/threads/abc123/artifacts/mnt/user-data/uploads/document.md"
}
],
"message": "Successfully uploaded 1 file(s)"
}
Name collisions: filenames are claimed unique against the thread's existing uploads and reserved atomically — a same-name upload never replaces the existing file; it lands as document_1.pdf (the response's filename/original_filename reflect the claimed name). Use the artifacts PUT endpoint for sanctioned in-place updates.
Supported Document Formats (auto-converted to Markdown):
- PDF (
.pdf) - PowerPoint (
.ppt,.pptx) - Excel (
.xls,.xlsx) - Word (
.doc,.docx)
List Uploaded Files
GET /api/threads/{thread_id}/uploads/list
Response:
{
"files": [
{
"filename": "document.pdf",
"size": 1234567,
"path": ".deer-flow/threads/abc123/user-data/uploads/document.pdf",
"virtual_path": "/mnt/user-data/uploads/document.pdf",
"artifact_url": "/api/threads/abc123/artifacts/mnt/user-data/uploads/document.pdf",
"extension": ".pdf",
"modified": 1705997600.0
}
],
"count": 1
}
Delete File
DELETE /api/threads/{thread_id}/uploads/{filename}
Response:
{
"success": true,
"message": "Deleted document.pdf"
}
Thread Cleanup
Remove DeerFlow-managed local thread files under .deer-flow/threads/{thread_id} after the LangGraph thread itself has been deleted.
DELETE /api/threads/{thread_id}
Response:
{
"success": true,
"message": "Deleted local thread data for abc123"
}
Error behavior:
422for invalid thread IDs500returns a generic{"detail": "Failed to delete local thread data."}response while full exception details stay in server logs
Projects
Get Projects Config
GET /api/projects/config
The projects config-block knobs the UI needs for client-side validation. Requires the projects:read scope (PATs included).
Response:
{
"instructions_max_bytes": 8192,
"trash_retention_days": 30
}
Values come from projects.instructions_max_bytes and projects.trash_retention_days in config.yaml; the documented defaults apply when the block is absent.
Project Documents
Per-project document shelf (Projects Phase 2). All routes fail closed: a missing or foreign project/document is 404 (never 403); uploads and individual trash require an active project — archived projects answer 404 for those while keeping reads; a memory-backend deployment answers 503 "Projects not available". Trashed rows are invisible to every route.
List Documents
GET /api/projects/{project_id}/documents?limit=100&offset=0
Query Parameters: limit (default 100, 1..1000), offset (default 0) — out-of-bounds values are 422.
Response: {"documents": [{"id", "name", "size_bytes", "sha256", "source_thread_id", "source_kind", "source_name", "created_at", "updated_at", "content_missing"}], "total", "limit", "offset"} in updated_at DESC, id ASC order. content_missing is read-time truth (never persisted): true when the document's immutable original is missing or size-mismatched (external interference); the derived converted.md companion is not the integrity anchor.
Upload Document
POST /api/projects/{project_id}/documents
Content-Type: multipart/form-data
Exactly one file per request (file part), plus an optional name form field (defaults to the multipart filename). The name is rejected with 400 when empty after normalization, separator-bearing, or over 255 UTF-8 bytes; empty files are 400; files over uploads.max_file_size are 413.
Response: 201 Created with {"document": {...}, "deduplicated": false}. Re-uploading identical content returns the existing row with 200 OK and "deduplicated": true — the first writer's name wins. Re-upload after trash creates a fresh row.
Save Thread File to Shelf (from-thread)
POST /api/projects/{project_id}/documents/from-thread
Content-Type: application/json
{"thread_id": "abc123", "kind": "upload", "name": "report.pdf", "shelf_name": "q3-report.pdf"}
Copies one file from the thread's own uploads ("kind": "upload") or outputs ("kind": "output") directory into the shelf as a project-owned snapshot; the source file is never moved. name locates the source file inside the thread; shelf_name is optional and defaults to the source name, following upload-name validation (400). A source that does not resolve inside that thread's directory — separator-bearing names, escapes, missing files, or a missing/foreign thread — is 404, indistinguishable from absence. Files over uploads.max_file_size are 413; empty files are 400.
Response: same as Upload Document — 201 Created with {"document": {...}, "deduplicated": false}, or 200 OK on a content dedup hit. The created row records source_thread_id / source_kind / source_name provenance.
Attach Document to Thread
POST /api/projects/{project_id}/documents/{document_id}/attach-to-thread/{thread_id}
Materializes an independent copy of a live shelf document into the target thread's uploads directory through the same ingestion pipeline as an ordinary upload (filename claiming, size checks, optional conversion under uploads.auto_convert_documents, sandbox-readable permissions, and sandbox sync for non-mounted providers; a caller denied sandbox:execute keeps the host upload without allocating a sandbox). Reading an archived source project's shelf is allowed and does not mutate it; a missing/foreign document, or a target thread the caller cannot write, is 404. A row whose original bytes are missing or size-mismatched answers 409 "content_missing".
Response: 200 OK with {"filename", "size_bytes", "virtual_path", "artifact_url"} — returned only after ingestion succeeds.
Get Document Content
GET /api/projects/{project_id}/documents/{document_id}/content?download=false
Serves the converted-markdown companion when present, else inline text when the original samples as text, else an attachment; download=true always attaches. Active content (text/html, text/xml, application/xml, text/xsl, any +xml type such as XHTML/SVG) is always forced to an attachment regardless of download, mirroring the artifacts router, so it never executes script on the application origin. A row whose original bytes are missing or size-mismatched answers 409 "content_missing".
Delete Document (move to trash)
DELETE /api/projects/{project_id}/documents/{document_id}
Response: 204. Recoverable trash: the row keeps its bytes and a {project_id, project_name} origin snapshot. Deleting a project moves its whole shelf to trash in the same transaction. Restore/purge endpoints land with the trash-completion slice.
Project Thread Files
Read-only conversation-files view over a project's member threads (Projects Phase 2) — the discovery route for Save Thread File to Shelf. Archived projects keep read access; a missing or foreign project is 404.
List Thread Files
GET /api/projects/{project_id}/thread-files?offset=0&thread_limit=20&file_limit=50
Query Parameters: offset (member-thread cursor, default 0), thread_limit (default 20, 1..50), file_limit (per-thread file cap, default 50, 1..200) — out-of-bounds values are 422.
Response: {"groups": [{"thread_id", "display_name", "updated_at", "truncated", "files": [{"kind": "upload"|"output", "name", "size_bytes", "modified_at", "artifact_url"}]}], "next_offset", "truncated"}. Member threads are paged in the same non-archived order as the project thread list; next_offset is null when no threads remain. Each thread contributes up to file_limit files across its uploads and outputs; a group's truncated is true when that thread's listing was cut, and the envelope truncated is the OR over the page's groups. Entries disappear when their thread is deleted — the view keeps no storage of its own.
Trash
Recoverable deletion tier for project shelf documents (Projects Phase 2). Trashed rows keep their bytes and a {project_id, project_name} origin snapshot for projects.trash_retention_days (default 30) before the retention sweep may purge them; permanent purge is a separate action. All routes fail closed: a missing or foreign document/project is 404 (never 403), restoring into an archived or foreign target is the same 404, and a memory-backend deployment answers 503 "Projects not available". Purge endpoints carry no confirmation parameter — the "this cannot be undone" step is a UI contract, not a server-enforced handshake.
List Trashed Documents
GET /api/trash/documents?limit=100&offset=0
Query Parameters: limit (default 100, 1..1000), offset (default 0) — out-of-bounds values are 422.
Response: {"documents": [{"id", "name", "size_bytes", "sha256", "source_thread_id", "source_kind", "source_name", "created_at", "updated_at", "trashed_at", "trash_origin": {"project_id", "project_name"} | null}], "total", "limit", "offset"}, most recently trashed first. The retention sweep runs lazily before the listing (a sweep failure is logged and never blocks it).
Restore Document
POST /api/trash/documents/{document_id}/restore
Content-Type: application/json
{"project_id": "…"}
Body: project_id optional. Target = the body value, else trash_origin.project_id when that project still exists, is owned, and is active; otherwise 404 (the UI offers the project picker). A foreign or archived target is the same 404 as a missing one.
Response: {"outcome": "restored" | "merged", "document": <ProjectDocumentResponse>}. merged means the target already had an active row with identical bytes: the trash row is deleted and document is the surviving active row. Restore re-points the row without moving any file. Missing or size-mismatched content answers 409 "content_missing" and leaves the row trashed.
Purge Document
POST /api/trash/documents/{document_id}/purge
Response: 204. Permanently unlinks the original and derived/converted.md, then deletes the row, in one row-locked transaction. Already-absent content counts as removed; any other file-cleanup failure rolls back, keeps the trashed row, and answers 500 with a retryable message.
Empty Trash
POST /api/trash/purge
Response: {"purged": <int>} — permanently deletes every trashed document of the caller, regardless of age: the confirmation covers the whole listing, so the retention cutoff never gates this route. Each row goes through the same guarded row-locked transaction as the single-document purge — bytes first, then the row. A file-cleanup failure other than already-absent content answers 500 with a retryable message, leaving that row and every row not yet visited trashed. Retention expiry is enforced only by the sweep (lazily before GET /api/trash/documents and once at gateway startup).
Artifacts
Get Artifact
Download or view an artifact generated by the agent.
GET /api/threads/{thread_id}/artifacts/{path}
Path Examples:
/api/threads/abc123/artifacts/mnt/user-data/outputs/result.txt/api/threads/abc123/artifacts/mnt/user-data/uploads/document.pdf
Query Parameters:
download(boolean): Iftrue, force download with Content-Disposition header
Response: File content with appropriate Content-Type. HTML and XML documents (.html, .xml, .xhtml, .svg, and other +xml types) are always returned as attachments, regardless of download, so generated markup never renders in the application origin.
Scheduled Tasks
Owner-scoped task management for /workspace/scheduled-tasks. Reads need
threads:read; mutations need threads:write, and create, update, resume and
trigger also need runs:create.
GET /api/scheduled-tasks
POST /api/scheduled-tasks
GET /api/scheduled-tasks/{task_id}
PATCH /api/scheduled-tasks/{task_id}
DELETE /api/scheduled-tasks/{task_id}
POST /api/scheduled-tasks/{task_id}/pause
POST /api/scheduled-tasks/{task_id}/resume
POST /api/scheduled-tasks/{task_id}/trigger
GET /api/scheduled-tasks/{task_id}/runs?status=&limit=&offset=
GET /api/threads/{thread_id}/scheduled-tasks
POST /api/scheduled-tasks/preview-cron
Task fields. Create and PATCH accept title, prompt, schedule_type
(once | cron | interval), schedule_spec, timezone, context_mode,
thread_id, assistant_id, plus:
| Field | Type | Notes |
|---|---|---|
goal_objective |
string | null | What one run must achieve (at most 4000 characters after whitespace normalization); requires fresh_thread_per_run. |
max_runs |
integer | null | Safety cap: automatic runs over the task's lifetime (trial runs excluded); at least 1. |
end_at |
date-time | null | Safety cap: no automatic run after this time. Without a UTC offset it is wall-clock time in the task's timezone. |
stop_condition |
string | null | The user's "stop when …" rule, stored in its own field. Whitespace collapses to single spaces; at most 500 characters; blank means none. It is never part of prompt: each launch appends it as an instruction to call stop_scheduled_task (or, with scheduler.tool_enabled off, to report a met rule). |
In a PATCH, sending null clears goal_objective, max_runs, end_at or
stop_condition; for every other field null means unchanged (assistant_id: null restores lead_agent). PATCH may change schedule_type together with
schedule_spec. Changing the goal, prompt or stop_condition starts a new
count for the automatic pause after three unmet runs. A PATCH that changes the
schedule of a finished task re-arms it (then its safety cap applies); a PATCH
that only changes the cap leaves a finished task finished.
Task responses (list, get, create, PATCH, pause, resume) return the stored task
plus automatic_runs_used (integer) and active_run_status (queued |
launching | running | null). A recurring task's status stays enabled
while its run executes, so check active_run_status for "is a run active".
GET /api/threads/{thread_id}/scheduled-tasks rows add thread_relation
(origin: created in the chat, reuse: runs in the chat, run: the chat is
one of its runs) and thread_run ({"run_number", "trigger", "scheduled_for", "status"} for run, else null).
Create returns 409 scheduler_not_running (after the request validates)
while this Gateway process's scheduler is not running; the tasks page's
Duplicate is a create.
Pause of a completed, failed or cancelled task returns 409 task_finished.
Resume accepts an optional renewal body:
{ "max_runs": 70, "end_at": "2026-12-31T18:00:00" }
Each field is optional; null clears that cap (a chat-created task that runs
more often than hourly must keep one: 422 frequent_requires_limit). The next
run is the stored one when still ahead, otherwise computed from now, so no
catch-up run happens; a one-time task whose time passed returns 422 once_time_passed. Resuming an enabled task changes nothing. A task whose
safety cap is used up returns 409 limits_exhausted unless the same request
renews the limit named in params.limit: for max_runs, a max_runs above
params.used or null; for end_at, a later end_at or null. A later
end_at alone does not renew a used-up max_runs.
A future end_at that falls before the next run returns 422 end_at_before_first_run (also on a PATCH that changes the schedule).
Trigger (one trial run) returns:
{ "id": "task-…", "triggered": true, "outcome": "launched", "existing": false, "thread_id": "…" }
outcome is launched or queued; existing: true means a run was already
waiting and no trial was added.
Runs rows add run_number (the automatic-run number counted like
max_runs; null for trials and runs that never launched), total_tokens of the
launched run (null if none), and summary (first line of the agent's final
reply as plain text; when that line ends with a colon, the list items that
follow it are appended, joined with ; for CJK text and ; otherwise; at
most 160 characters).
Errors (breaking change). Every error these routes raise for a well-typed request is coded:
{ "detail": { "code": "limits_exhausted", "message": "All 5 automatic runs are used. Raise max_runs above 5 or clear it (max_runs: null) in the same request to reactivate.", "params": { "limit": "max_runs", "used": 5, "max_runs": 5, "end_at": null } } }
message stays English for API clients; params is omitted when empty.
Clients that read detail as a string must read detail.message instead.
Three errors keep their old shape: a 403 from route permissions is the plain
string "Permission denied: <permission>", FastAPI's own 422 for malformed
JSON or wrong types (for example "max_runs": "abc") keeps its list detail,
and the shared 503 "Thread metadata store not available" (a Gateway without
a thread store) stays a plain string. Codes the web UI translates: invalid_request, invalid_schedule, invalid_schedule_type, invalid_timezone, interval_too_short, interval_too_long, once_in_past, once_too_soon, once_time_passed, invalid_context_mode, reuse_thread_requires_thread, thread_not_found, invalid_assistant, unknown_assistant, invalid_goal, goal_requires_fresh_thread, invalid_stop_condition, invalid_max_runs, end_at_in_past, end_at_before_first_run, frequent_requires_limit, max_runs_not_above_used, limits_exhausted, task_not_found, task_running, run_queued, task_changed, task_finished, task_quota_exceeded, scheduler_not_running, scheduler_unavailable (503: this Gateway has no scheduled-task persistence), trigger_failed. Codes only the chat capability
returns: timezone_required, authentication_required, permission_denied, scheduler_tools_disabled, authority_expired, conversation_not_found, interactive_run_required, unsupported_action, unsupported_fields, task_id_required, note_not_verbatim, note_limit_reached, trial_requires_direct_request, no_stop_authority, occurrence_not_active. The machine-readable list is
contracts/scheduled_task_errors_contract.json.
Feature flag. GET /api/features includes:
{ "scheduled_tasks": { "available": true, "running": true, "tool_enabled": false, "min_interval_seconds": 60 } }
available: the task APIs have persistence. running: this process's
scheduler poller runs (tasks fire and can be created). tool_enabled: chats
can manage tasks and scheduled runs can stop their own schedule.
min_interval_seconds: shortest interval and earliest one-time delay.
Browser timezone for chat-created tasks. A run request may carry
context.client_timezone (an IANA name, at most 64 characters, for example
"Asia/Shanghai"). It is read only as the default timezone of tasks the
schedule_task tool creates in that turn; an unknown or malformed value is
ignored, and it never reaches the run config, the checkpoint or the prompt.
Scheduled run messages. A scheduled run's prompt message has the id
scheduled-<task_run_id> and carries additional_kwargs.deerflow_scheduled_origin
(task_id, task_run_id, trigger, run_number, scheduled_for, timezone,
schedule_type, task_title, instructions, stop_condition,
standing_notes), the user-written parts a client shows instead of the
launched text. Show an interval run's time in the viewer's zone (its stored
timezone may be the "UTC" placeholder of a task created without one) and
other runs in timezone. A new run conversation is titled
"{task title} · MM-DD HH:MM" in the task's zone, or "{task title} · #{run}"
when that zone is only the placeholder. The key is server-owned: it is
stripped from client-supplied messages and state updates.
Error Responses
Most APIs return errors in this format (scheduled-task routes and skill export return a coded object instead; see Scheduled Tasks):
{
"detail": "Error message describing what went wrong"
}
HTTP Status Codes:
400- Bad Request: Invalid input404- Not Found: Resource not found422- Validation Error: Request validation failed500- Internal Server Error: Server-side error
Authentication
DeerFlow supports four HTTP identity sources. They share the same thread/run isolation rules but differ in whether a row is created in users and how external identities are mapped. See AUTH_DESIGN.md for the full design.
| Model | Entry | users table |
Isolation key |
|---|---|---|---|
| Browser session | access_token cookie after login/register |
Yes | users.id |
| OIDC / SSO | OAuth callback → cookie | Yes | users.id (see SSO.md) |
| IM channel binding | Connect code + channel_connections |
Bound to registered user | channel_connections.owner_user_id |
| Internal Auth | X-DeerFlow-Internal-Token + X-DeerFlow-Owner-User-Id |
No | Owner string on threads_meta.user_id |
IM channel binding and Internal Auth are both platform-trust integrations: DeerFlow trusts the channel/platform to authenticate end users. IM bindings persist the mapping in channel_connections / channel_conversations and require a DeerFlow users row. Internal Auth lets a platform call the Gateway API directly with a deployment-shared token and a per-request owner header—no users row, but thread/run/checkpoint isolation works the same way.
Browser session (default)
DeerFlow enforces authentication for all non-public HTTP routes. Public routes are limited to health/docs metadata and these public auth endpoints:
POST /api/v1/auth/initializecreates the first admin account when no admin exists.POST /api/v1/auth/login/locallogs in with email/password and sets an HttpOnlyaccess_tokencookie.POST /api/v1/auth/registercreates a regularuseraccount and sets the session cookie.POST /api/v1/auth/logoutclears the session cookie.GET /api/v1/auth/setup-statusreports whether the first admin still needs to be created.
The authenticated auth endpoints are:
GET /api/v1/auth/mereturns the current user.POST /api/v1/auth/change-passwordchanges password, optionally changes email during setup, incrementstoken_version, and reissues the cookie.
Protected state-changing requests also require the CSRF double-submit token: send the csrf_token cookie value as the X-CSRF-Token header. Login/register/initialize/logout are bootstrap auth endpoints: they are exempt from the double-submit token but still reject hostile browser Origin headers.
User isolation is enforced from the authenticated user context:
- Thread metadata is scoped by
threads_meta.user_id; search/read/write/delete APIs only expose the current user's threads. - Thread files live under
{base_dir}/users/{user_id}/threads/{thread_id}/user-data/and are exposed inside the sandbox as/mnt/user-data/. - Memory and custom agents are stored under
{base_dir}/users/{user_id}/....
Note: MCP outbound connections can still use OAuth for configured HTTP/SSE MCP servers; that is separate from DeerFlow API authentication.
Internal Auth (platform HTTP integration)
For server-to-server integrations (e.g. a Feishu or WeCom/Enterprise WeChat bot backend), configure:
export DEER_FLOW_INTERNAL_AUTH_TOKEN="<long-random-secret>"
| Header | Required | Description |
|---|---|---|
X-DeerFlow-Internal-Token |
Yes | Must match DEER_FLOW_INTERNAL_AUTH_TOKEN; missing/invalid → 401 |
X-DeerFlow-Owner-User-Id |
Yes for per-user isolation | Platform user id (e.g. feishu_ou_alice, wecom_user_bob); omit → default bucket |
Does not use browser cookies or CSRF tokens. Does not insert into users; sets threads_meta.user_id / runs.user_id from the owner header. DeerFlow validates only the platform token—not whether the owner id represents a real end user; user validity is entirely the platform's responsibility. See AUTH_DESIGN.md — Internal Auth for trust boundaries, persistence, and security notes.
Use the standard Gateway thread/run endpoints (POST /api/threads, POST /api/threads/{thread_id}/runs/stream, etc.) with the headers above on every request.
Rate Limiting
No rate limiting is implemented by default. For production deployments, configure rate limiting in Nginx:
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://backend;
}
Streaming Support
Gateway's LangGraph-compatible API streams run events with Server-Sent Events (SSE).
Thread-scoped streaming (thread must exist):
POST /api/langgraph/threads/{thread_id}/runs/stream
Accept: text/event-stream
Stateless streaming (no pre-created thread; Gateway auto-creates one):
POST /api/langgraph/runs/stream
Accept: text/event-stream
Both endpoints return Content-Location: /api/threads/{thread_id}/runs/{run_id}.
The DeerFlow web UI and LangGraph SDK clients rely on this header to discover the
assigned thread_id and run_id on the first message of a new chat.
SSE replay retention and gaps
Clients may reconnect to a run stream with Last-Event-ID. Replay history is
bounded by stream_bridge.queue_maxsize (default 256) and, for Redis, by the
rolling stream_ttl_seconds. A retained cursor resumes after that event with no
additional control frame.
When a syntactically valid cursor is older than the retained watermark, the
server sends exactly one gap event before any retained data and closes that
subscription without an end event:
event: gap
data: {"code":"stream_replay_gap","run_id":"run-123","requested_event_id":"1718000000000-1","earliest_available_event_id":"1718000000100-42","latest_available_event_id":"1718000000200-84","recovery":"reload_durable_state"}
The frame deliberately has no SSE id:. Both earliest_available_event_id and
latest_available_event_id are string | null (they are null when no events
are retained in the buffer). Consumers must reload durable thread state and
persisted run events/messages, then may reconnect from latest_available_event_id
to follow newer live events, or rejoin without a cursor when the buffer is empty
(latest_available_event_id is null). A gap does not cancel the active run.
The same signal applies when a no-cursor subscriber has already established an
empty-stream wait but the first Redis wake-up falls behind before delivery; in
that case requested_event_id is null. Malformed cursor handling is
backend-specific and is not the same as a valid cursor that was evicted.
SDK Usage
Python (LangGraph SDK)
from langgraph_sdk import get_client
client = get_client(url="http://localhost:2026/api/langgraph")
run_meta: dict[str, str] = {}
def on_run_created(meta) -> None:
# langgraph-sdk 0.3.x parses Content-Location only when this callback is set.
if meta.thread_id:
run_meta["thread_id"] = meta.thread_id
run_meta["run_id"] = meta.run_id
# Option A: stateless stream — no thread pre-creation
# Gateway auto-creates a thread and returns thread_id/run_id in Content-Location.
async for event in client.runs.stream(
None,
"lead_agent",
input={"messages": [{"role": "user", "content": "Hello"}]},
config={"configurable": {"model_name": "gpt-4"}},
stream_mode=["values", "messages-tuple", "custom"],
on_run_created=on_run_created,
):
print(event)
thread_id = run_meta["thread_id"] # persist before the next turn
# Option A (continued): same thread on the next turn
async for event in client.runs.stream(
None,
"lead_agent",
input={"messages": [{"role": "user", "content": "What did I just ask?"}]},
config={"configurable": {"thread_id": thread_id, "model_name": "gpt-4"}},
stream_mode=["values", "messages-tuple", "custom"],
on_run_created=on_run_created,
):
print(event)
# Option B: thread-scoped stream — create thread first, then stream
thread = await client.threads.create()
async for event in client.runs.stream(
thread["thread_id"],
"lead_agent",
input={"messages": [{"role": "user", "content": "Hello"}]},
config={"configurable": {"model_name": "gpt-4"}},
stream_mode=["values", "messages-tuple", "custom"],
on_run_created=on_run_created,
):
print(event)
JavaScript/TypeScript
// Using fetch for Gateway API
const response = await fetch('/api/models');
const data = await response.json();
console.log(data.models);
function parseRunLocation(contentLocation: string | null) {
if (!contentLocation) return null;
const match = /\/threads\/([^/]+)\/runs\/([^/]+)/.exec(contentLocation);
if (!match) return null;
return { threadId: match[1], runId: match[2] };
}
// Option A: stateless stream — no thread pre-creation
let threadId: string | undefined;
const firstResponse = await fetch("/api/langgraph/runs/stream", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "text/event-stream",
},
body: JSON.stringify({
input: { messages: [{ role: "user", content: "Hello" }] },
stream_mode: ["values", "messages-tuple", "custom"],
}),
});
const created = parseRunLocation(firstResponse.headers.get("Content-Location"));
threadId = created?.threadId;
console.log("thread_id:", created?.threadId, "run_id:", created?.runId);
// Option B: continue the same thread on the next turn
const followUpResponse = await fetch("/api/langgraph/runs/stream", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "text/event-stream",
},
body: JSON.stringify({
input: { messages: [{ role: "user", content: "What did I just ask?" }] },
config: { configurable: { thread_id: threadId } },
stream_mode: ["values", "messages-tuple", "custom"],
}),
});
// Option C: thread-scoped stream when you already have a thread_id
const streamResponse = await fetch(`/api/langgraph/threads/${threadId}/runs/stream`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "text/event-stream",
},
body: JSON.stringify({
input: { messages: [{ role: "user", content: "Hello" }] },
stream_mode: ["values", "messages-tuple", "custom"],
}),
});
const reader = streamResponse.body?.getReader();
// Decode and parse SSE frames from reader in your client code.
cURL Examples
# List models
curl http://localhost:2026/api/models
# Get MCP config
curl http://localhost:2026/api/mcp/config
# Upload file
curl -X POST http://localhost:2026/api/threads/abc123/uploads \
-F "files=@document.pdf"
# Enable skill
curl -X PUT http://localhost:2026/api/skills/pdf-processing \
-H "Content-Type: application/json" \
-d '{"enabled": true}'
# Stateless stream — no thread pre-creation
curl -s -D - -N -X POST http://localhost:2026/api/langgraph/runs/stream \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"input": {"messages": [{"role": "user", "content": "Hello"}]},
"config": {
"recursion_limit": 100,
"configurable": {"model_name": "gpt-4"}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}'
# Read Content-Location: /api/threads/{thread_id}/runs/{run_id} from the headers.
# Continue the same thread on the next turn
curl -s -N -X POST http://localhost:2026/api/langgraph/runs/stream \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"input": {"messages": [{"role": "user", "content": "What did I just ask?"}]},
"config": {
"configurable": {"thread_id": "abc123", "model_name": "gpt-4"}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}'
# Thread-scoped flow — create thread first, then stream
curl -X POST http://localhost:2026/api/langgraph/threads \
-H "Content-Type: application/json" \
-d '{}'
curl -X POST http://localhost:2026/api/langgraph/threads/abc123/runs/stream \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"input": {"messages": [{"role": "user", "content": "Hello"}]},
"config": {
"recursion_limit": 100,
"configurable": {"model_name": "gpt-4"}
},
"stream_mode": ["values", "messages-tuple", "custom"]
}'
The unified Gateway path defaults
config.recursion_limitto 100 for plan-mode and subagent-heavy runs. Clients may still setconfig.recursion_limitexplicitly — see the Create Run section for details. Scheduled-task launches usescheduler.recursion_limitfromconfig.yamlinstead of a client body.
Chat archive and restore
POST /api/threads/search accepts archived: true for archived chats or
archived: false for recent chats (including legacy rows without an archive flag).
Omit the field or use null to include both. Filtering applies before limit and
offset and is scoped to the authenticated user. Combine it with the existing
metadata and status filters when needed.
Archive with PATCH /api/threads/{thread_id} and body
{"metadata":{"deerflow_archived":true}}; use false to restore. The flag must be
a JSON boolean. Writes containing only boolean pin/archive flags preserve
updated_at and all other metadata. The owner-checked endpoint returns the normal
thread metadata response; original thread and artifact URLs remain available.
Archiving does not cancel runs, pause schedules, or change retention.