> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nixflex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add knowledge sources through the API

> Create an agent knowledge base, submit text or files for review, and discover website pages without mistaking preparation for publication.

**FIXED · agent** One live knowledge base belongs to an agent. Its attached numbers use that base on enabled channels. Only the active revision and eligible, unsuppressed pieces enter live retrieval.

**NOT OFFERED → do this instead · number** Knowledge and its enabled channels belong to the agent. Retired per-number knowledge operations return 410 number\_knowledge\_removed. Use separate agents when a number needs different knowledge or none.

**YOU CAN CHANGE · source** Use pasted text, PDF, DOCX or plain UTF-8 text, or discover a website and import selected pages. API submissions can request review.

**SCOPE · agent** Review knowledge drafts and publish approved material. Limits per base: `sources` 50 · `kbTokens` 100,000 · `topics` 1,000.

[Read the compact AI rules](https://docs.nixflex.com/ai-rules.md#knowledge)

Prepare text, files or selected website pages for an agent’s knowledge base, with review requested before new facts become live.

Input: **Text, files or selected pages** · Output: **Preparation job** · Next task: **Review the draft**

**The important part**

* Create one knowledge base for the agent, not for each number.
* Save the operation key and returned job ID before starting another import.
* Set review:true explicitly; the API default can publish after preparation.

[Business guide](https://docs.nixflex.com/guides/business/knowledge/add-facts.md) · [API reference](https://docs.nixflex.com/api-reference/introduction.md) · [Glossary](https://docs.nixflex.com/guides/glossary.md)

## Before you start

* An account API credential in `NIXFLEX_API_KEY` and an owned active agent ID in `NXF_AGENT_ID`.
* Knowledge enabled for the account. API-managed and mixed-origin agents can be hidden from dashboard knowledge screens while remaining accessible to the owning API key.
* A durable operation record in your application. Knowledge writes require an `Idempotency-Key`: 8–128 letters, digits, dots, underscores, colons or hyphens. The `prompt:` prefix is reserved. Use one key per intended operation and retain it across an uncertain response.

The examples use the production API address. Set the intended account credential privately in `NIXFLEX_API_KEY` before running anything. Knowledge examples require Node/CLI 0.11.0 or later or Python 0.4.0 or later.

## Create or read the base

Read [capabilities](https://docs.nixflex.com/api-reference/knowledge/get-knowledge-capabilities.md) and `GET /v1/agents/{agent_id}/knowledge-base`. The scope reply contains `own` and `effective`; they can be null before creation. Create the singleton with `PUT` at the same path, a new idempotency key and this body:

```json theme={"dark"}
{"settings":{"channels":["inbound"],"match":"Strict","not_found":"I don't have that information right now."}}
```

Save `own.id` as `NXF_KNOWLEDGE_BASE_ID` and its integer `rev`. An update to an existing base needs its current `expected_revision`. The settings channels are `inbound`, `outbound`, `web_voice`, `web_chat` and `sms`; only inbound starts enabled. Campaigns use outbound, with no separate campaign switch. `not_found` must be nonblank and at most 500 characters.

[Create or update an agent base](https://docs.nixflex.com/api-reference/knowledge/put-agents-target-knowledge-base.md) documents the scope envelope. Retired number-knowledge routes return 410; never create a number-level base. Old retained number-base rows are not automatically converted into live agent knowledge. Re-add the intended facts to the current agent and review them explicitly.

## Submit material for review

Set `NXF_IDEMPOTENCY_KEY` to a fresh operation key. The same text import is shown in all four tabs:

Use this body in each example. Save it as `request-112.json` for the CLI.

```json theme={"dark"}
{
  "source": {
    "type": "text",
    "title": "Appointments",
    "text": "Appointments are available Monday to Friday."
  },
  "review": true
}
```

```bash cURL (Bash) theme={"dark"}
curl --request POST \
  --url "https://api.nixflex.com/v1/knowledge-bases/$(node -p 'encodeURIComponent(process.env.NXF_KNOWLEDGE_BASE_ID)')/sources" \
  --header "Authorization: Bearer $NIXFLEX_API_KEY" \
  --header "Idempotency-Key: $NXF_IDEMPOTENCY_KEY" \
  --header "Content-Type: application/json" \
  --data '{"source":{"type":"text","title":"Appointments","text":"Appointments are available Monday to Friday."},"review":true}'
```

```javascript Node theme={"dark"}
import Nixflex from 'nixflex';
const c = new Nixflex({apiKey:process.env.NIXFLEX_API_KEY,baseUrl:'https://api.nixflex.com',maxRetries:0});
const result = await c.knowledge.addSource(process.env.NXF_KNOWLEDGE_BASE_ID, {"source":{"type":"text","title":"Appointments","text":"Appointments are available Monday to Friday."},"review":true}, {idempotencyKey:process.env.NXF_IDEMPOTENCY_KEY});
// Keep knowledge and private results out of logs.
```

```python Python theme={"dark"}
import os
from nixflex import Nixflex

with Nixflex(api_key=os.environ["NIXFLEX_API_KEY"], base_url="https://api.nixflex.com", max_retries=0) as c:
    result = c.knowledge.add_source(os.environ["NXF_KNOWLEDGE_BASE_ID"], {
      "source": {
        "type": "text",
        "title": "Appointments",
        "text": "Appointments are available Monday to Friday."
      },
      "review": True
    }, idempotency_key=os.environ["NXF_IDEMPOTENCY_KEY"])
    # Keep knowledge and private results out of logs.
```

```powershell CLI (PowerShell) theme={"dark"}
# Save the JSON above privately as request-112.json.
nixflex knowledge addSource "$env:NXF_KNOWLEDGE_BASE_ID" --body '@request-112.json' --idempotency-key "$env:NXF_IDEMPOTENCY_KEY" --confirm --json --base-url "https://api.nixflex.com"
```

`review:true` is deliberate. The public API defaults to false, which can publish after preparation; dashboard imports always require review. Flags and review reminders can force a draft even when false was requested.

For files, POST raw bytes to the same source endpoint with `Content-Type: application/octet-stream`, `X-Filename`, `X-Review: true` and the idempotency header. Do not send base64 or a local path. Supported contents are UTF-8 text, PDF with selectable text and DOCX. A preview via [source measure](https://docs.nixflex.com/api-reference/knowledge/post-agents-target-knowledge-base-source-measure.md) counts privately without saving a source; it is not publication clearance.

For websites, create a [discovery job](https://docs.nixflex.com/api-reference/knowledge/post-knowledge-bases-kb-website-discoveries.md), read its `result.pages`, let the user choose IDs, then submit `discovery_id`, `page_ids` and `review:true` to [website imports](https://docs.nixflex.com/api-reference/knowledge/post-knowledge-bases-kb-website-imports.md). A direct `source.type:url` or `qa` is refused.

## Check the accepted job

HTTP 202 means preparation was accepted. Save the job ID in the same application record as the base ID and idempotency key. Read the job until it reaches `needs_review`, `ready`, `failed`, `cancelled` or `deleted`. `ready` can also mean unchanged input; it does not by itself prove that new facts were published.

If the response is lost, retry the same intention with the original key and unchanged input. A new key could add a duplicate source. Honour `next_retry_at` and stop polling when the user leaves; resume from the saved job later.

## Fix rejected sources

| Result | Next step |
| - | - |
| 413 | Reduce the source or saved inventory; read current capabilities and usage. |
| 415 or 422 | Supply supported readable content; an image-only PDF needs selectable text or pasted text. |
| Safety check waiting | Follow the job retry time; do not bypass the configured scanner by repeatedly importing. |
| 409 revision conflict | Read the current base and review the intended change again. |
| 429 busy | Wait for current jobs; keep their existing IDs. |

Local file validation is not a complete virus scan. A configured but unavailable scanner may hold PDF or DOCX processing at `safety_check` or `safety_waiting` until its reported expiry.

## Continue the workflow

* [Review and publish the draft](https://docs.nixflex.com/guides/developer/knowledge/review-and-publish.md)
* [Read exact source fields and limits](https://docs.nixflex.com/api-reference/knowledge/post-knowledge-bases-kb-sources.md)
* [Understand source, job and topic IDs](https://docs.nixflex.com/concepts/knowledge.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.