> ## 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.

# Measure knowledge source

> Measure source token usage before import without storing or publishing the source. The preview does not reserve later quota.

**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)

Preview source token usage before an import without storing the source.

Method: **POST** · Success: **200** · Scope: **Owning account**

**The important part**

* Measure the proposed source before importing it.
* Measurement does not publish text or reserve quota for a later import.

[Business guide](https://docs.nixflex.com/guides/business/knowledge.md) · [Developer guide](https://docs.nixflex.com/guides/developer/knowledge.md) · [Glossary](https://docs.nixflex.com/guides/glossary.md)

## Authentication

Send Authorization: Bearer KEY\_ID:KEY\_SECRET using the owning account’s server-side API credential. API keys have Owner authority. Personal Owner and Admin may perform this action; Member is refused. Personal dashboard visibility can hide API-origin agents. Never send owner fields to select another account.

## Request fields

| Field | Type | Required | Default | Limits and meaning |
| - | - | - | - | - |
| `target` (path) | string | Yes | None | Owned agent ID. URL-encode it as a path segment. |
| `X-Filename` (header) | string | No | Omitted | Required for a raw upload; filename up to 200 characters. Use a genuine PDF, DOCX or UTF-8 text file. Maximum 200 characters. |
| `X-Source-Title` (header) | string | No | Omitted | Optional source title, at most 200 characters; defaults to filename. Maximum 200 characters. |
| `X-Review` (header) | string | No | Omitted | For imports: exactly true requests review; other/omitted values mean false for API requests. |

Send a JSON object.

| Field | Type | Required | Default | Limits and meaning |
| - | - | - | - | - |
| `text` | string | Yes | None | Text up to 10 MiB of UTF-8 bytes. Empty input returns allowed:false. |

This authenticated POST is a read-only calculation and needs no Idempotency-Key. It does not reserve capacity, call a paid model or save a file/base. Import checks totals again.

Raw upload: Content-Type application/octet-stream, X-Filename, optional X-Source-Title and X-Review; replacements also require X-Expected-Revision. File maximum 10 MiB; PDF maximum 200 pages. Accept clean UTF-8 text, PDF with selectable text, or DOCX. No raw base64/path input, RTF, executable or active-content documents. Preview scan status is not publication clearance. Without a configured scanner, local\_checks\_only permits bounded local checks. With a configured scanner, PDF/DOCX need a clean result; clean UTF-8 text can use local checks during an outage. Infected files never bypass. Imports may wait at safety\_check/safety\_waiting with next\_retry\_at; after 24 hours scan\_expired requires a new upload. Raw files are private and never downloaded; accepted storage retains extracted text.

## Response fields

`200 OK` returns the fields below. Where this operation queues work, follow the job and current revision until it finishes ([accepted is not confirmed](https://docs.nixflex.com/guides/glossary.md#saved-accepted-and-confirmed)).

| Field | Type | Meaning |
| - | - | - |
| `tokens` | integer | Saved value. |
| `limit` | integer | Value: `20000`. |
| `used` | integer | Saved value. |
| `total_limit` | integer | Value: `100000`. |
| `projected` | integer | Saved value. |
| `allowed` | boolean | Saved value. |
| `scan_status` | string | Allowed: `"checked"`, `"local_checks_only"`, `"text_checks_only"`, `"pending"`, `"not_needed"`. |

## Example request

These examples target Node/CLI 0.11.0 and Python 0.4.0; confirm the installed version supports the method before use. The cURL tab uses Bash; CLI uses PowerShell. Python shows sync usage; AsyncNixflex uses the same JSON methods with async with and await. Set the account credential in `NIXFLEX_API_KEY` and the owned path identifiers shown below in environment variables. Submit this calculation deliberately.

```json request-69.json theme={"dark"}
{
  "text": "Appointments are available Monday to Friday."
}
```

```bash cURL (Bash) theme={"dark"}
curl --request POST \
  --url "https://api.nixflex.com/v1/agents/$(node -p 'encodeURIComponent(process.env.NXF_AGENT_ID)')/knowledge-base/source-measure" \
  --header "Authorization: Bearer $NIXFLEX_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"text":"Appointments are available Monday to Friday."}'
```

```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.measureSource(process.env.NXF_AGENT_ID, {"text":"Appointments are available Monday to Friday."});
// 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.measure_source(os.environ["NXF_AGENT_ID"], {
      "text": "Appointments are available Monday to Friday."
    })
    # Keep knowledge and private results out of logs.
```

```powershell CLI (PowerShell) theme={"dark"}
# Save the JSON below privately as request-69.json.
nixflex knowledge measureSource "$env:NXF_AGENT_ID" --body '@request-69.json' --confirm --json --base-url "https://api.nixflex.com"
```

```json MCP theme={"dark"}
{
  "name": "measure_knowledge_source",
  "arguments": {
    "target": "target/example",
    "text": "Example source text."
  }
}
```

MCP has 97 registered tools, including 19 Knowledge tools. This example uses a registered tool; configure its credentials and permissions separately.

## Example response

Illustrative response; identifiers are placeholders and optional fields can be absent.

```json Response theme={"dark"}
{
  "tokens": 0,
  "limit": 20000,
  "used": 0,
  "total_limit": 100000,
  "projected": 0,
  "allowed": false,
  "scan_status": "checked"
}
```

## Errors

Failures use `error.type`, `error.code`, `error.message`, `error.doc_url` and optional `error.details`. Knowledge failures include a request ID in details when available. Read the safe message as text. A job can return HTTP 200 with state `failed` and `error`; that is a job failure, not an HTTP error. Source failures can arise during preparation after the initial accepted response.

| Status | Code | Meaning | What to do |
| - | - | - | - |
| 400 | [`invalid_input`](https://docs.nixflex.com/api-reference/errors#invalid_input) | Check the information and try again. | Correct the named fields or reduce the input before retrying. |
| 404 | [`not_found`](https://docs.nixflex.com/api-reference/errors#not_found) | That topic is not available. | Check the owned identifier and feature availability. |
| 409 | [`deleting`](https://docs.nixflex.com/api-reference/errors#deleting) | This knowledge base is being deleted. | Read current state and resolve the conflict before sending a new request. |
| 503 | [`unavailable`](https://docs.nixflex.com/api-reference/errors#unavailable) | Knowledge is unavailable right now. Your saved information is safe. Try again. | Retry reads with bounded backoff; reconcile writes before repeating. |
| 503 | [`knowledge_unconfigured`](https://docs.nixflex.com/api-reference/errors#knowledge_unconfigured) | Knowledge is not available yet. | Retry reads with bounded backoff; reconcile writes before repeating. |
| 503 | [`knowledge_not_released`](https://docs.nixflex.com/api-reference/errors#knowledge_not_released) | Knowledge is not released yet. | Retry reads with bounded backoff; reconcile writes before repeating. |
| 403 | [`permission_denied`](https://docs.nixflex.com/api-reference/errors#permission_denied) | Your personal role does not allow this action. | Use a permitted personal account; do not share the organisation key. |
| 403 | [`membership_revoked`](https://docs.nixflex.com/api-reference/errors#membership_revoked) | Your membership has ended. | Use a permitted personal account; do not share the organisation key. |
| 401 | [`unauthorized`](https://docs.nixflex.com/api-reference/errors#unauthorized) | The credential is missing or invalid. | Check the full account credential. |
| 429 | [`rate_limit_exceeded`](https://docs.nixflex.com/api-reference/errors#rate_limit_exceeded) | The account request limit was reached. | Wait for the stated retry/reset time. |
| 429 | [`measure_busy`](https://docs.nixflex.com/api-reference/errors#measure_busy) | Other files are being checked. Please try again in a moment. | Wait for the stated retry/reset time. |
| 503 | [`measure_unavailable`](https://docs.nixflex.com/api-reference/errors#measure_unavailable) | Counting took too long. Try a smaller source or try again. | Retry reads with bounded backoff; reconcile writes before repeating. |
| 413 | [`source_limit`](https://docs.nixflex.com/api-reference/errors#source_limit) | This source contains too much text. Split it into smaller documents. | Correct the named fields or reduce the input before retrying. |
| 400 | [`invalid_body`](https://docs.nixflex.com/api-reference/errors#invalid_body) | The request body could not be read. | Correct the named fields or reduce the input before retrying. |
| 415 | [`wrong_type`](https://docs.nixflex.com/api-reference/errors#wrong_type) | The file contents do not match its type. Use a genuine PDF, DOCX or plain UTF-8 text file. | Correct the named fields or reduce the input before retrying. |
| 415 | [`unsupported_file`](https://docs.nixflex.com/api-reference/errors#unsupported_file) | Use PDF, DOCX or plain UTF-8 text. Rich text and executable files are not accepted. | Correct the named fields or reduce the input before retrying. |
| 422 | [`empty_file`](https://docs.nixflex.com/api-reference/errors#empty_file) | This file is empty. Choose a file containing text. | Correct the named fields or reduce the input before retrying. |
| 413 | [`file_limit`](https://docs.nixflex.com/api-reference/errors#file_limit) | This file is too big. Choose a file up to 10 MiB. | Correct the named fields or reduce the input before retrying. |
| 422 | [`unclean_text`](https://docs.nixflex.com/api-reference/errors#unclean_text) | This file is not clean UTF-8 text. Save it as UTF-8 without binary data or hidden control characters. | Correct the named fields or reduce the input before retrying. |
| 422 | [`unsafe_file`](https://docs.nixflex.com/api-reference/errors#unsafe_file) | This file failed the virus safety check. Use a clean copy or paste clean text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`unsafe_pdf`](https://docs.nixflex.com/api-reference/errors#unsafe_pdf) | This PDF contains scripts, actions or embedded files. Export a clean text-only PDF or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`unsafe_word`](https://docs.nixflex.com/api-reference/errors#unsafe_word) | This Word file contains macros, embedded files or active content. Save a clean DOCX or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`password_pdf`](https://docs.nixflex.com/api-reference/errors#password_pdf) | This PDF is password protected. Remove the password from a copy or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`scanned_pdf`](https://docs.nixflex.com/api-reference/errors#scanned_pdf) | This PDF has a page with no readable text. Use a text PDF, convert the scanned pages to text, or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`page_limit`](https://docs.nixflex.com/api-reference/errors#page_limit) | This PDF has more than 200 pages. Split it into smaller documents. | Correct the named fields or reduce the input before retrying. |
| 422 | [`archive_limit`](https://docs.nixflex.com/api-reference/errors#archive_limit) | This Word document expands beyond the safe size limit. Save a smaller DOCX or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`unreadable`](https://docs.nixflex.com/api-reference/errors#unreadable) | This file is damaged or could not be read safely. Save a new copy or paste the text. | Correct the named fields or reduce the input before retrying. |
| 422 | [`parse_timeout`](https://docs.nixflex.com/api-reference/errors#parse_timeout) | Reading this file took too long. Try a smaller document or paste the text. | Correct the named fields or reduce the input before retrying. |
| 503 | [`scan_unavailable`](https://docs.nixflex.com/api-reference/errors#scan_unavailable) | Safety check in progress. We will retry automatically. | Retry reads with bounded backoff; reconcile writes before repeating. |
| 415 | [`unsafe_word`](https://docs.nixflex.com/api-reference/errors#unsafe_word) | This Word file contains macros, embedded files or active content. Save a clean DOCX or paste the text. | Use a clean DOCX or paste clean text. |
| 413 | [`invalid_body`](https://docs.nixflex.com/api-reference/errors#invalid_body) | The request body is too large. | Keep the transport body within 10 MiB. |

## Retry and idempotency

This is a read or calculation. GET requests may retry transient connection failures once with bounded backoff; respect Retry-After. Do not retry invalid input or ownership errors unchanged. POST calculations are not automatically retried.

## Related endpoints

* [Get knowledge capabilities](https://docs.nixflex.com/api-reference/knowledge/get-knowledge-capabilities.md)
* [List knowledge agents](https://docs.nixflex.com/api-reference/knowledge/get-knowledge-targets.md)
* [Errors and recovery](https://docs.nixflex.com/api-reference/errors.md#error-envelope)


## OpenAPI

````yaml api-reference/public.openapi.json POST /agents/{target}/knowledge-base/source-measure
openapi: 3.1.0
info:
  title: Nixflex public API
  version: 1.0.0
  description: >-
    Nixflex API reference for agents, calls, messaging, knowledge, organisations
    and integrations. Authenticate with the owning account and follow each
    operation’s permissions, response and retry contract.
servers:
  - url: https://api.nixflex.com/v1
security:
  - bearerAuth: []
paths:
  /agents/{target}/knowledge-base/source-measure:
    post:
      tags:
        - Knowledge
      summary: Measure knowledge source
      description: >-
        Preview source token usage before an import without storing the source.
        This authenticated POST is a read-only calculation and needs no
        Idempotency-Key. It does not reserve capacity, call a paid model or save
        a file/base. Import checks totals again.


        Raw upload: Content-Type application/octet-stream, X-Filename, optional
        X-Source-Title and X-Review; replacements also require
        X-Expected-Revision. File maximum 10 MiB; PDF maximum 200 pages. Accept
        clean UTF-8 text, PDF with selectable text, or DOCX. No raw base64/path
        input, RTF, executable or active-content documents. Preview scan status
        is not publication clearance. Without a configured scanner,
        local_checks_only permits bounded local checks. With a configured
        scanner, PDF/DOCX need a clean result; clean UTF-8 text can use local
        checks during an outage. Infected files never bypass. Imports may wait
        at safety_check/safety_waiting with next_retry_at; after 24 hours
        scan_expired requires a new upload. Raw files are private and never
        downloaded; accepted storage retains extracted text.
      operationId: post_agents_target_knowledge_base_source_measure
      parameters:
        - name: target
          in: path
          required: true
          schema:
            type: string
            description: Owned agent ID. URL-encode it as a path segment.
        - name: X-Filename
          in: header
          required: false
          schema:
            type: string
            description: >-
              Required for a raw upload; filename up to 200 characters. Use a
              genuine PDF, DOCX or UTF-8 text file.
            maxLength: 200
        - name: X-Source-Title
          in: header
          required: false
          schema:
            type: string
            description: >-
              Optional source title, at most 200 characters; defaults to
              filename.
            maxLength: 200
        - name: X-Review
          in: header
          required: false
          schema:
            type: string
            description: >-
              For imports: exactly true requests review; other/omitted values
              mean false for API requests.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                text:
                  type: string
                  description: >-
                    Text up to 10 MiB of UTF-8 bytes. Empty input returns
                    allowed:false.
              required:
                - text
              additionalProperties: true
              description: ''
            example:
              text: Appointments are available Monday to Friday.
          application/octet-stream:
            schema:
              type: string
              format: binary
              description: >-
                Raw PDF, DOCX or UTF-8 text, at most 10 MiB. Supply X-Filename.
                Replacement also requires X-Expected-Revision.
      responses:
        '200':
          description: Successful response.
          content:
            application/json:
              schema:
                type: object
                properties:
                  tokens:
                    type: integer
                    description: ''
                  limit:
                    type: integer
                    description: ''
                    const: 20000
                  used:
                    type: integer
                    description: ''
                  total_limit:
                    type: integer
                    description: ''
                    const: 100000
                  projected:
                    type: integer
                    description: ''
                  allowed:
                    type: boolean
                    description: ''
                  scan_status:
                    type: string
                    description: ''
                    enum:
                      - checked
                      - local_checks_only
                      - text_checks_only
                      - pending
                      - not_needed
                required:
                  - tokens
                  - limit
                  - used
                  - total_limit
                  - projected
                  - allowed
                  - scan_status
                additionalProperties: true
                description: ''
        '400':
          description: >-
            invalid_input: Check the information and try again. invalid_body:
            The request body could not be read.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '401':
          description: 'unauthorized: The credential is missing or invalid.'
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '403':
          description: >-
            permission_denied: Your personal role does not allow this action.
            membership_revoked: Your membership has ended.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '404':
          description: 'not_found: That topic is not available.'
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '409':
          description: 'deleting: This knowledge base is being deleted.'
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '413':
          description: >-
            source_limit: This source contains too much text. Split it into
            smaller documents. file_limit: This file is too big. Choose a file
            up to 10 MiB. invalid_body: The request body is too large.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '415':
          description: >-
            wrong_type: The file contents do not match its type. Use a genuine
            PDF, DOCX or plain UTF-8 text file. unsupported_file: Use PDF, DOCX
            or plain UTF-8 text. Rich text and executable files are not
            accepted. unsafe_word: This Word file contains macros, embedded
            files or active content. Save a clean DOCX or paste the text.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '422':
          description: >-
            empty_file: This file is empty. Choose a file containing text.
            unclean_text: This file is not clean UTF-8 text. Save it as UTF-8
            without binary data or hidden control characters. unsafe_file: This
            file failed the virus safety check. Use a clean copy or paste clean
            text. unsafe_pdf: This PDF contains scripts, actions or embedded
            files. Export a clean text-only PDF or paste the text. unsafe_word:
            This Word file contains macros, embedded files or active content.
            Save a clean DOCX or paste the text. password_pdf: This PDF is
            password protected. Remove the password from a copy or paste the
            text. scanned_pdf: This PDF has a page with no readable text. Use a
            text PDF, convert the scanned pages to text, or paste the text.
            page_limit: This PDF has more than 200 pages. Split it into smaller
            documents. archive_limit: This Word document expands beyond the safe
            size limit. Save a smaller DOCX or paste the text. unreadable: This
            file is damaged or could not be read safely. Save a new copy or
            paste the text. parse_timeout: Reading this file took too long. Try
            a smaller document or paste the text.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '429':
          description: >-
            rate_limit_exceeded: The account request limit was reached.
            measure_busy: Other files are being checked. Please try again in a
            moment.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
        '503':
          description: >-
            unavailable: Knowledge is unavailable right now. Your saved
            information is safe. Try again. knowledge_unconfigured: Knowledge is
            not available yet. knowledge_not_released: Knowledge is not released
            yet. measure_unavailable: Counting took too long. Try a smaller
            source or try again. scan_unavailable: Safety check in progress. We
            will retry automatically.
          content:
            application/json:
              schema:
                type: object
                required:
                  - error
                properties:
                  error:
                    type: object
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      doc_url:
                        type: string
                      details:
                        type: object
                        additionalProperties: true
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        KEY_ID:KEY_SECRET from the owning account. Keep it server-side. A
        verified personal dashboard Bearer session may be used where the
        operation documents role-based access.

````

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