Skip to content
←Back to Open Source

OPEN SOURCE DEEP DIVE

DeepSeekLLM ClientAnthropic-Compatible APILocal-First

DeepSeek Chat Demo: a local-first chat client with no application backend

A static TypeScript chat client that calls an Anthropic-compatible DeepSeek API directly, keeps chats and files in the browser, and serves as an inspectable API integration reference.

deepseek-ai/chat-demo3.0kTypeScriptMIT12 min read

DeepSeek Chat Demo is an official example repository from DeepSeek. It is neither a model wrapper nor a complete multi-user chat service. Its purpose is to show how a browser can talk directly to DeepSeek's Anthropic-compatible API while still offering the interaction quality users expect from a modern chat application: conversations, attachments, message branches, search, citations, voice input, read-aloud playback, and history import/export. The important architectural decision is that the repository supplies no application backend of its own. Inference, file storage, automatic speech recognition, and speech synthesis all happen in the configured remote API; the browser owns presentation, local state, and stream reconstruction.

That distinction matters more than the phrase "no backend" suggests. The project does not include a business server, database, or authentication gateway. It still depends on an API service. A user enters an API key in Settings, and the browser then makes cross-origin requests to that service. The production build can be placed on static hosting, copied to a local folder, or opened through a file URL. None of this changes the fact that messages, attachments, and audio are sent to the remote API when those features are used.

What the repository actually owns

LayerImplemented in this repositoryLeft outside the repository
User interfaceA bilingual React and TypeScript chat client with settings, a conversation sidebar, message actions, and mobile layoutsAccounts, teams, roles, and permissions
Protocol accessMessages and Files APIs, model-key validation, ASR, and TTSThe models themselves, inference scheduling, and remote content safety services
StateSettings in localStorage; conversations, message trees, and attachment blobs in IndexedDBCross-device synchronization and centralized recovery
DeliveryA static Rspack build that can run on ordinary web hostingSecret storage for the API key, server-side rate limits, and centralized audit logs

This scope is useful because many chat demos stop at a single request and a single response. A real client has to deal with stopped streams, rejected responses, attachment retries, branch selection, restored history, generated titles, and continuation rules. DeepSeek Chat Demo exposes those states without hiding the API behind a custom server, so the source remains a practical bridge between protocol documentation and a working interface.

The request path and the compatible message protocol

The build injects an API origin, which defaults to https://api.deepseek.com. Chat requests go to /anthropic/v1/messages; uploads and file deletion use /anthropic/v1/files; API-key verification uses the model-list endpoint. The default chat model is deepseek-flash, with a second model identifier available in the client types. A request is not a plain text string. It carries a system prompt, structured messages, a thinking switch, a safety level, server tools, and an optional title-generation instruction.

The safety level is always high. Link reading is always declared as a server tool, while web search follows the user's setting. The title extension lets the service propose a conversation title in the final message event. Continuation is represented by sending the existing assistant content as the tail of the message list, not by inventing a complete answer on the client. Only completed question-and-answer pairs enter later context. Failed, refused, template-only, and unusable tool turns are omitted.

Responses use text/event-stream. The repository includes its own SSE decoder instead of assuming that each network chunk contains one clean event. It supports CRLF, LF, and CR line endings, concatenates multi-line data, ignores keep-alive comments, and uses a streaming UTF-8 decoder so a multibyte character split across chunks is not corrupted. Events are dispatched only on a blank line, and an incomplete event at end of stream is not treated as valid. The chat layer considers a response complete only after message_stop; an early close becomes an interruption error rather than a quietly truncated success.

The client preserves the structure of each Anthropic-compatible content block. Text blocks keep their citations; thinking blocks keep text and signatures; server-tool blocks preserve search, page opening, find-in-page, and link-reading actions; the final delta records the stop reason and cumulative usage. Streaming deltas are mapped through a temporary block index into local reply blocks. Unknown events are skipped so a protocol extension does not immediately break older clients. Stop generation uses an AbortController against both the request and the stream reader, leaving the received content available for display and, when the protocol allows it, continuation.

Local-first state without pretending to be a server

The application separates preferences from conversation assets. The API key, language, theme, location, read-aloud voice, thinking and search switches, and sidebar state live in localStorage. Conversation summaries, full message trees, and original file blobs live in IndexedDB. That split makes preferences cheap to restore at startup and keeps large binaries out of string-based key-value storage. Session summaries have an attachment index, and blobs are keyed by a local file identifier so multiple messages can reference the same original without storing duplicate copies.

Uploads begin before the user sends the message. After a selection, paste, or drop, the client validates extension, size, and count before placing work in a queue with at most three concurrent uploads. Images do not receive a document-processing purpose; PDF, Word, and PowerPoint files use rich-layout recognition; text, code, spreadsheets, and ebooks use the user-data purpose. General files are capped at 64 MB, user-data files at 32 MB, and one message can contain up to 50 files, subject to server-side validation.

The message ultimately refers to the uploaded file by its remote identifier. If a restored attachment has a local blob but no remote identifier, the client uploads it again before sending. If the original is gone, the client does not invent an identifier or silently send a partial reference. Images become image blocks and other files become document blocks. Source comments also record an important protocol limit: extended mode does not support document blocks, so a file being selectable in the interface does not guarantee that every model mode can process it.

Deleting a local conversation removes its messages and any blobs no longer referenced by other conversations. It does not delete files already uploaded to the API. The clear-all action follows the same rule and explicitly preserves the API key and settings. This is reasonable for a demo, but a production implementation must add remote-file cleanup, quota reconciliation, retention rules, and a user-facing deletion workflow that covers both sides of the boundary.

Branches, regeneration, and history archives

A conversation is a tree rather than an append-only list. Each message has a parent and a selected child; both the visible transcript and later request context follow the active path. Regeneration creates a sibling answer under the same parent. Switching versions changes the selected child and restores that branch's later path without destroying the alternative. Editing a question uses the same structure, which lets several formulations and their subsequent discussion coexist. This is more reliable than replacing text in place and also gives imported history enough information to restore a selected path.

History exchange uses a version 3 ZIP format. An export starts with a manifest, then writes session JSON, a session index, and locally available image files. The importer also accepts valid layouts in which sessions and images are interleaved and the index appears last. It checks the format version, paths, sizes, CRCs, index membership, message-tree rules, and archive completeness. Parsed records first enter a staging object store. Only after every check succeeds does one IndexedDB transaction replace the active conversations and files; a failure or closed page leaves the previous data intact.

The archive preserves the full message tree and original image bytes available on the device. It excludes API keys, settings, and original non-image attachments. Message text, thinking duration, template markers, tool results, and link-reading signatures survive, while model choice, some usage details, non-selected branches, and structured error metadata do not fully survive. Imported replies are deliberately marked as non-continuable. Import, export, and clear-all share a serial queue so two large storage operations cannot interleave.

Search, link reading, citations, and refusal handling

Smart search is not a client-side crawler. The request declares server-side tools, and the remote service performs searches, page opens, find-in-page operations, and link reads. Result blocks can contain titles, URLs, snippets, site metadata, page age, and encrypted content. Citations attached to text include the URL, title, and the cited text up to that point. The interface displays the source material it can safely use while retaining or ignoring encrypted values according to the protocol.

A successful link read includes a signature. On a later turn, the client returns the matching read_link tool call and result only when both remain valid, allowing the service to recover the page context. It does not rerun every historical search or expose all prior thinking. The client also distinguishes an ordinary stop, an output-length stop, a client-tool stop, and a refusal. If the service returns a refusal, the client removes already streamed text and thinking from the local reply and keeps tool blocks, matching the protocol rule that refused generated content must not remain visible or enter later context.

Continuation is intentionally narrow. It is available for a reply the user stopped or for a normally completed reply that hit the output limit. It is unavailable for errors, refusals, client tool calls, turns containing server-tool blocks, and template-only messages. These are protocol constraints, not missing UI work. Anyone adapting the demo should model them explicitly rather than enabling a button and hoping the service accepts an invalid prefix.

Voice, rich rendering, and the limits of file-mode operation

Voice input is captured in the page as 16 kHz, mono, 16-bit PCM WAV for up to 120 seconds. The recording graph feeds an analyser as well as the encoder, which is why the mobile input row can show a live spectrum. The resulting WAV is posted to the ASR endpoint. Read-aloud requests a raw PCM stream at 24 kHz and schedules decoded chunks in order, allowing playback once the first audio arrives. The server is asked to filter code blocks, tables, citation markers, and long equations so read-aloud does not become a literal recital of formatting.

Markdown, syntax highlighting, KaTeX, and Mermaid are supported. The Rspack build derives asset paths from the current script location, which allows asynchronous chunks and fonts to load relative to the application even when it is opened from a local directory. A file URL is still not a universal deployment target: the browser must permit storage for that origin, and the API must accept the resulting cross-origin request. Browser policies differ, so file-mode operation is useful for demos and local trials but should not be treated as a dependable enterprise distribution mechanism.

Static delivery and the security boundary

Rspack produces a static directory, injects the API origin at build time, and copies the license into the output. There is no backend entry point or proxy route. Consequently, the API key must exist in storage that browser JavaScript can reach. localStorage is not encryption. A same-origin script compromise, malicious extension, another person using the same browser profile, or a compromised static-hosting dependency can read the key. Removing the application server does not remove security work; it moves the trust boundary into the browser and the API service's CORS policy.

A product derived from this code should at minimum use a restricted dedicated key or short-lived token, hide long-lived credentials behind a server proxy, apply per-user rate limits to generation and uploads, implement server-side file deletion and quota tracking, audit requests, harden against XSS and third-party scripts, decide whether conversations may synchronize across devices, and define retention and content-safety procedures. Putting a privileged production key into a public static deployment makes that key readable and abusable by every visitor.

The direct model is nevertheless valuable for internal tools, personal workbenches, protocol validation pages, and controlled demos. It makes it easy to confirm whether a service supports thinking, search, link signatures, file blocks, title generation, and the exact event sequence the client expects. With no application server in the middle, failures are easier to attribute either to local state management or to the remote API.

Where it fits and where it does not

The project is a strong reference for evaluating DeepSeek's Anthropic-compatible API, establishing a feature baseline for a custom chat product, studying robust browser-side SSE handling, testing search and citation flows, validating attachments and speech, or running a local client on a controlled network. Its message-tree branching, staged archive replacement, upload queue, refusal cleanup, and continuation rules are substantially closer to real use than a minimal message list.

It should not be treated as the complete foundation for accounts, team permissions, cross-device synchronization, centralized audit, secret isolation, shared file cleanup, or shared conversations. It is also a poor fit for an organization that needs administrators to recover browser-only history. If any of those requirements matter, keep the protocol and interaction lessons but add an application server with a clear credential and data boundary.

Bottom line

DeepSeek Chat Demo is best understood as a complete browser-side reference implementation for a DeepSeek-compatible chat API. Its most valuable source code is not the number of screens but the handling of real failure modes: interrupted SSE streams, attachment re-uploads, branching conversations, transactional history import, signed link context, refusal cleanup, and guarded continuation.

The adoption decision starts with one question: is it acceptable for the browser to be the API client and for the deployment model to define key and retention policy? When the answer is yes, this repository is a dense starting point for a personal or controlled chat interface. When the answer is no, the missing backend is a required product component, not a detail that can be inferred from a static build.

Related Projects

deepseek-ai/deepseek-harnessMIT

DeepSeek Harness: the open-source agent runtime where everything is a plugin

DeepSeek AI's open-source agent harness (CLI dsh, MIT, 233k+ stars). The kernel provides only plugin-system semantics; tools, surfaces and model access all attach as plugins, on top of Cordis' paradigm for spatiotemporal composability (arXiv:2608.25512). It is in developer preview with an explicit warning about compatibility-breaking changes, and SAFETY.md is required reading before you run it. Not benchmarked yet, so this entry is graded as needing reproduction.

Agent HarnessPlugin Architecture
TypeScript234k28k1.0k
bowenliang123/dsh-contextApache-2.0

dsh-context: turning DeepSeek Harness context into an auditable ledger

A DeepSeek Harness plugin for context insight and management: five surfaces cover the cross-session overview, per-session composition/trend/events/file activity and the subagent fleet; the host folds the V4 durable event log into a per-request composition timeline, meters parity-verified against the runtime own projections, and probes a per-tag compatibility matrix against real harness sources.

Agent ContextLLM Agent
TypeScript2.8k979
deepseek-ai/DeepInferApache-2.0

DeepInfer: The Inference Framework Behind DeepSeek's Production Serving

DeepSeek's open-sourced production inference engine: offline serving for DeepSeek-V4.1-Flash on NVIDIA SM100 and Ascend 950, with a C++ zero-overhead scheduler, attention DP/CP plus MoE EP with EPLB, DSpark confidence-scheduled speculative decoding, SWA bounded replay, batch-invariant and deterministic modes, and structured outputs under Apache-2.0.

LLM InferenceInference Framework
Python1.8k1291
deepseek-ai/dsh-libreoffice-kitMPL-2.0

DeepSeek open-sources dsh-libreoffice-kit: font-friendly Office conversion & rendering for Node.js agents

Open-sourced internal component of DeepSeek Harness (npm @deepseek-ai/libreoffice-kit + dsoffice CLI): Office-to-PDF export (OOXML + 97-2003 binary), spreadsheet recalculation, and page-by-page PNG rendering of Office/PDF inputs. Font-friendly = font discovery / preserve requested families / configurable fallbacks (Carlito for Calibri, Caladea for Cambria) / missingFonts reporting and budgets. Prebuilt engines for macOS ARM64/x64, Windows ARM64/x64 and Linux WASM bundle offline, with downloads slimmed 37-39%; no dependence on a user LibreOffice install.

DeepSeeklibreoffice
JavaScript4120

As an Amazon Associate, we earn from qualifying purchases.