Dify Knowledge API and dataset-scoped API keys

A planning guide to automating document ingestion into Dify knowledge bases with the Knowledge API, binding keys to specific datasets and keeping credentials server side.

On this page

Dify Knowledge API and scoped keys: when automated ingestion makes sense

Automate document ingestion through the Knowledge API when a team must load documents into Dify knowledge bases on a schedule or directly from source systems, and manual uploads in the console can no longer keep the content current. Console uploads suit one-off loads, small collections and content that someone reviews before it is indexed. The Knowledge API suits repeatable pipelines, where the documents, their update frequency and their target knowledge base are known in advance. Confirm the endpoints and their behavior in the Dify API reference for your version, because the reference defines what the API can create, update and delete. Dataset-scoped keys arrived in 1.17.1, released on September 10, 2026, so a pipeline can hold a key that reaches only the knowledge base it feeds. This page applies to self-hosted Community and Enterprise deployments in your own infrastructure.

The first decisions are ownership and boundaries. Name the team that owns each pipeline, the knowledge bases it writes to and the source system that is the record of truth. If a source already has a sync or export mechanism, reuse it rather than building a second copy of the logic. Sensitive document sets should sit in their own knowledge bases, so a pipeline key for one set cannot reach another. A workspace allows 10 API keys, so one key per pipeline is workable only with a naming scheme and a rotation owner. Sharing one broad key across several pipelines removes the separation you are trying to create. Before going live, run the pipeline against a non-production knowledge base and confirm that a key bound to one dataset is refused by any other dataset. Indexing also consumes embedding model calls on your own accounts, so confirm those costs with the team that manages model access.

Keep every key on the server side. The pipeline job should read its key from your secrets manager at run time, call the Knowledge API from your scheduler or service, and never place the key in a browser, a mobile app, a front-end bundle or a shared configuration file. Dataset-scoped binding only works on 1.17.1 or later, so pin your upgrade plan to the release notes on the Dify releases page and test the binding behavior on that version before you rely on it. Plan rotation and revocation as part of operations: when a pipeline is retired or its owner changes, the key should be revoked on the same day, and the audit trail should show who created it and what it wrote.

Choosing between workspace-wide and dataset-scoped API keys

A workspace-wide key authenticates against the Knowledge API for every knowledge base in the workspace. It fits one ingestion job that feeds a general corpus owned by one team, because setup is a single credential with no per-dataset mapping. The trade-off is that its reach grows with the workspace, so a knowledge base created later is reachable with the same key without any further change.

  • Blast radius: A leaked key can read, add, or delete documents in every knowledge base in the workspace, including sets that other teams created for sensitive material.
  • Management effort: One key is simple to track, but rotation touches every job that holds it, so a rotation window affects all ingestion at once.
  • Fit for general sets: It suits public product documentation or internal policies where exposure is acceptable and a single team owns every knowledge base.
  • Attribution: Calls made with a shared key are harder to tie to one pipeline, which slows investigation after an unexpected change.

Before choosing this scope, list every knowledge base in the workspace and confirm that the key's pipeline needs write access to each one.

Key configuration options and when each fits

This table compares the main choices for scoping and storing Knowledge API keys, along with the operating effort each one adds. Read each row against your ingestion pattern and the 10-key workspace limit, then confirm the exact key screens and binding options in your Dify version. The main takeaway is that narrower scope and server-side storage add upkeep but limit the damage if a key leaks.

OptionWhen it fitsOperating effort it adds
Key bound to one knowledge baseSensitive document sets that need their own access boundary. Binding is available from 1.17.1, so confirm it in your version.One key per dataset to create, record and rotate. Confirm the binding screen before relying on it.
Shared key for a whole workspaceA single small pipeline with one owner and low-sensitivity documents.Fewer keys to manage, but one leaked key exposes every dataset the workspace holds.
One key per pipelineSeparate ingestion jobs, such as a nightly sync and a manual upload tool, run by different owners.Each job needs its own rotation and a named owner. Every key counts toward the 10-key workspace limit.
One key per teamTeams that own separate source systems and need to revoke access without affecting others.Requires agreed ownership and a clear record of which team holds which key.
Descriptive naming conventionAny estate with more than a few keys, so audits and revocations stay quick.Agree a standard upfront, such as purpose, dataset and owner, and enforce it in the admin process.
Scheduled rotationLong-running ingestion jobs, where a leaked key or departing owner requires replacing the credential.A runbook per job and a planned cutover window. Unplanned rotation interrupts running syncs.
Server-side storage in a secrets managerEvery production pipeline, with keys injected at runtime into the jobs that call the Knowledge API.Integration work with CI/CD and the vault, plus periodic reviews of who can read the secret.
Keys in browser code or shared documentsThrowaway tests in an isolated environment only.Low setup effort, but any exposure requires revoking and reissuing the key.

Setting up scoped Knowledge API access step by step

This sequence gives an automated ingestion job a key that can write only to the knowledge bases it needs, with the key held on the server and each step checked before the next begins. It produces a tested, documented setup that a team can repeat in staging and production.

  1. Confirm the Dify version

    The platform team checks the running Dify version against the GitHub releases page. Dify 1.17.1 was released on September 10, 2026, and bound dataset-scoped keys are available from that version. If the instance is older, plan the upgrade with the upgrade guide for the target version before continuing. Done when the version shown in the console or deployed image tag is 1.17.1 or later and the team has recorded it in the change ticket.

  2. Back up before any change

    Before creating keys or changing knowledge base settings, the operator takes a backup of the metadata database, vector store, file storage and the .env file, following the Docker Compose upgrade guidance to back up before every change. Confirm the backup is complete and labeled with the current version. Done when the team has a backup set that someone other than the operator can locate, and ideally one restore test has been run in a non-production copy.

  3. Map knowledge bases and access rules

    The data owner and the Dify administrator list each knowledge base the ingestion job will touch, the document classes it holds, and who is allowed to use it in apps. Sensitive document sets should sit in their own knowledge bases so a key can be scoped to them alone. Done when the list is signed off by the data owner and every target knowledge base has a named owner and a documented access rule.

  4. Create the key bound to target bases

    An administrator creates a dataset-scoped key in the Dify console and binds it only to the knowledge bases from the approved list. Before creating it, check how many keys the workspace already holds against the workspace key limit shown in your version. Record the key identifier, the bound knowledge base names and the creator in the change record. Done when the key's detail view lists exactly the approved bases and no others.

  5. Store the key in a server-side secret store

    The platform team places the key in the organization's server-side secret manager and gives the ingestion service read access to that secret alone. The key must not appear in browser code, mobile apps, shared scripts, source repositories or chat tools. Done when a repository and front-end bundle scan finds no copy of the key, and the ingestion service reads it from the secret store at runtime.

  6. Run a test ingestion to one base

    The engineer sends one test document through the Knowledge API using the stored key, targeting a single knowledge base that is meant for testing or is the designated pilot. Check that the document appears in that knowledge base and that indexing completes with the chunk mode and index method the owner approved. Done when the document is listed in the intended knowledge base and the engineer has noted the request time and response in the change record.

  7. Verify the key is refused elsewhere

    The engineer repeats the same kind of call against a knowledge base that is not in the key's binding, both to write and to read, and confirms each attempt is rejected. Then the engineer removes the test document and checks the audit or application logs for the rejected attempts. Done when every out-of-scope call fails, the rejections are visible in logs, and the test document is removed from the pilot base.

How to keep Knowledge API keys server side

Knowledge API keys must never reach browsers, mobile apps or client-side scripts. A dataset-scoped key can create and update documents in the knowledge base it is bound to, so anyone who reads it from a page source, an app bundle or a network trace can write to that knowledge base. Keep the calls that use the key inside a backend service or a scheduled ingestion job that you control. The front end should call your own service, which checks the caller's identity and then makes the Knowledge API request on its behalf. Treat the key like a database password: it belongs in the process that needs it and nowhere else.

Inject the key at runtime from a secrets store or from environment variables supplied by your orchestrator, and keep it out of source code, container images, sample notebooks and CI logs. Separate keys per knowledge base and per job make rotation and revocation far less disruptive. Keep the SECRET_KEY setting in a separate category. The environment reference says it signs session cookies and JWTs and encrypts OAuth credentials, and changing it after deployment logs out all users, so it is a platform secret to plan for during upgrades and recovery, not a substitute for Knowledge API credentials. Confirm with your security team whether your vault integrates with your container platform, and document who can read the injected values.

Restrict outbound network access from the ingestion job. A job that reads documents from source systems and pushes them to Dify should only reach the Dify API endpoint, the approved document sources and your logging service. Enforce this at the network layer with egress rules or an allowlisted proxy, since an application-level setting alone will not stop a compromised job from sending the key elsewhere. Dify's SSRF_PROXY settings cover requests Dify makes outward, but they do not govern your own job's traffic, so check that path separately. Confirm the exact endpoint, authentication header and key format against the current Dify API documentation for your version before you write the job.

Security risks in automated document ingestion

Automated ingestion places a standing credential into scripts, pipelines and hosts that often receive less review than the Dify console. The risks below share one root: a key that can write to a knowledge base is only as safe as the place it is stored, the scope it carries and the process that retires it. Each card names the control to plan before the first automated upload.

Key leakage through front-end code or logs

A Knowledge API key placed in browser code, a shared spreadsheet, a CI log or an error trace gives anyone who finds it write access to every base the key covers. Plan for keys to exist only in server-side code and a secret store, and add log redaction so the key never appears in request logs or crash output. Search every repository, build log and error handler for the key string before go-live, and again after each pipeline change.

Over-broad workspace keys

A key that reaches every knowledge base in a workspace turns one leaked credential into access to all of them, including sensitive sets that should stay separate. Confirm in your Dify version whether a key can be bound to a single knowledge base, and plan one key per base for each ingestion job. Broad keys are often created for a one-time test and then kept, so review their scope at every change window.

Shared keys across pipelines

When one key serves a nightly import, a sync job and a manual upload script, a failure or rotation in one pipeline breaks the others and makes the audit trail hard to read. Give each pipeline its own key, named for its purpose and owner, so that revoking one leaves the rest running. Record which key wrote each document so that a bad import can be traced back to its source and its key.

Unvetted source documents with sensitive data

Automated ingestion moves whatever a source system exports into the index, including personal data, credentials pasted into notes and confidential contracts. Once indexed, that material can be retrieved by every app that uses the base. Plan a review step for new sources, classify documents before they reach a base, and send regulated document sets to their own knowledge bases with their own keys.

Outbound request exposure from the ingestion host

Ingestion jobs that fetch files or pages from URLs can be pointed at internal addresses if the host has broad network reach. Dify's SSRF_PROXY settings route outbound requests through a proxy that blocks internal and private IP ranges, so confirm those settings are active on the Dify server for every path your jobs use. Limit the ingestion host's outbound access to the sources it actually needs.

Key rotation gaps

Keys that are never rotated stay valid after staff change roles, scripts are retired or a laptop is lost. Plan a rotation schedule and a procedure that creates the replacement key, updates the pipeline and only then revokes the old one. Keep an inventory that maps each key to its owner and knowledge base, and rotate API keys separately from SECRET_KEY, which signs sessions and logs out all users when changed.

Questions teams ask before automating Knowledge API ingestion

What does automating Knowledge API ingestion cost?

The cost follows the written scope, so the main drivers are how many document sources feed Dify, how many knowledge bases and API keys the pipeline touches, and how much error handling your team needs. Most work falls into source discovery and metadata mapping, building and testing the ingestion service, key storage and access design, logging, and handover. Most of this is one-time. Recurring effort comes from source changes, new Dify minor releases and key rotation. The self-hosted Community edition is free and limited to one workspace, according to the Dify pricing page, so the software license is rarely the largest line. Ask for an itemized quote with separate phases, a named list of knowledge bases in scope, and an explicit statement of what is excluded, including post-handover support.

How long does a Knowledge API integration take to build?

Duration depends mostly on how quickly you can provide the inputs: a source inventory, the knowledge base structure, a non-production workspace and a decision on who owns the pipeline. The upload code itself is short. Time goes into edge cases: large files, failed uploads that need safe retries, documents that change or get deleted, and checks that a document actually reached the index. Confirm your file size and batch limits and the Nginx body size before you set a schedule, because they determine how uploads must be split. Ask for milestones tied to acceptance tests in the written scope, so each stage has a visible finish point.

What do we need to provide before an integration starts?

Prepare six inputs before any build begins:

  • A named inventory of document sources and the owner of each source
  • The target knowledge bases, their chunk and index settings, and the teams allowed to read them
  • A non-production Dify instance running the same version as production
  • Access to the secrets store or vault where API keys will be kept
  • Network rules that let the ingestion runner reach the Dify API, plus an approval path for creating new keys
  • Sample documents and written acceptance tests

The key inventory matters early because each workspace allows 10 Knowledge API keys, so the plan must show which pipeline uses which key before you create any.

Can our internal team build this without a partner?

Yes, if the team includes engineers who can build an ingestion service with retries, idempotent uploads, logging and alerting, and if someone owns Dify upgrades after go-live. Read the Knowledge API documentation for your exact Dify version before you design anything, because behavior differs between releases. The main design risks are the 10-key workspace limit, which requires an inventory and a reuse plan, and per-knowledge-base key binding, which arrived in 1.17.1 and changes how you split keys. Installations on earlier versions need a different plan. A partner is useful when the team lacks capacity or wants a fixed-scope build with written acceptance tests. DeployOpen implements these integrations inside your infrastructure under a written scope.

How do we rotate Knowledge API keys without downtime?

Rotate with an overlap window. Create the new key while the old one still works, load the new key into the ingestion runner from your secrets store, confirm that uploads succeed with it, and only then revoke the old key. Because each workspace allows 10 keys, record which pipeline uses which key and keep a naming convention, so you never run out of slots during rotation. Store keys server side only, never in browser code, front-end configuration or shared scripts. Write the procedure, rehearse it in a staging workspace and log each rotation. Ask whether your Dify version supports the binding you need before you rely on a specific rotation sequence.

What changes when we upgrade Dify?

Upgrades follow the guide for the target version on the GitHub Releases page, and you should take a backup before every upgrade. Check .env.example for new variables after the upgrade. Minor releases arrive roughly monthly: 1.16.0 on July 17, 2026, 1.17.0 on August 25, 2026 and 1.17.1 on September 10, 2026. Key-binding behavior from 1.17.1 means that an upgrade can change what a key may access, so re-run your acceptance tests after each upgrade, including a test that a key cannot write to a knowledge base outside its binding. Hold ingestion jobs during the upgrade window, then confirm that document counts and index status match your records before resuming.

Should Knowledge API keys be scoped per knowledge base or shared?

Scoped keys limit the damage from a leaked key, because a pipeline can reach only the knowledge bases it needs. Shared keys are simpler to manage but expose every knowledge base if a key is compromised. Sensitive document sets should have their own knowledge base and their own key, and access to those bases should follow your access model. Since 1.17.1, Dify supports binding keys to specific knowledge bases. Confirm that behavior in the documentation for your version and test it directly by attempting an upload with a key to a base it should not reach. Record the result as part of your change evidence.

How DeployOpen scopes and supports Dify ingestion work

DeployOpen plans, implements, hardens, documents and supports self-hosted Dify inside your own infrastructure, including the document ingestion automation that feeds your knowledge bases. We agree the scope in writing before work starts, so the key model, ingestion pipeline and handover are defined before any code is written.

How we scope

  • Inventory which knowledge bases automated uploads will touch and which document sets need their own keys
  • Confirm the Dify version in use, since binding keys to a knowledge base depends on 1.17.1 or later
  • Map each ingestion job to its owner, source system, schedule and the key it will use
  • Agree in writing what the engagement covers, which is fixed-scope, with ongoing support available as a retainer

How we build

  • Create dataset-scoped keys per knowledge base and plan around the 10-key workspace limit
  • Keep all Knowledge API calls in server-side services, with keys held in your secrets store rather than in client code
  • Build retry, duplicate detection and failure logging into the ingestion scripts so reruns do not create duplicate documents
  • Test uploads against file size and batch limits configured in your environment before scaling volume

How we hand over

  • Deliver a key register listing each key, its knowledge base, owner, rotation steps and revocation procedure
  • Document the ingestion architecture, request flows, error codes and the settings that affect each knowledge base
  • Run a handover session with your platform and security teams that covers rotation and incident response for keys
  • Provide test scripts and runbooks so your engineers can repeat verification after upgrades

How we support

  • Review key scopes and ingestion jobs when Dify releases change API authentication or knowledge base behavior
  • Check release notes and upgrade guides before each planned upgrade, with a backup taken first
  • Rotate keys and retest ingestion on a schedule agreed in the retainer, if you choose one
  • Confirm with your team which support hours and response paths apply before the engagement starts

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.