PyAI Knowledge Bases API

Hosted knowledge bases for Omni grounding: create a base, add documents (file upload, URL fetch, or pasted text), then bind it to agent profiles or set org-wide defaults. Bound bases are retrieved per turn, no `kb_endpoint` of your own required.

GitHub OpenAPI

Operations 14

GET /v1/knowledgebases List knowledge bases #
POST /v1/knowledgebases Create a knowledge base #
GET /v1/knowledgebases/default List org-default KB bindings #
PUT /v1/knowledgebases/default Set org-default KB bindings #
GET /v1/knowledgebases/{id} Get a knowledge base (with documents) #
PATCH /v1/knowledgebases/{id} Rename a knowledge base #
DELETE /v1/knowledgebases/{id} Delete a knowledge base #
GET /v1/knowledgebases/{id}/documents List documents in a knowledge base #
POST /v1/knowledgebases/{id}/documents Add a document (file, URL, or text) #
POST /v1/knowledgebases/{id}/crawls Crawl a public website into a knowledge base #
PATCH /v1/knowledgebases/{id}/documents/{docId} Edit a pasted-text document #
DELETE /v1/knowledgebases/{id}/documents/{docId} Remove a document #
GET /v1/knowledgebases/{id}/documents/{docId}/content Inspect a document's extracted content #
POST /v1/knowledgebases/{id}/documents/{docId}/retry Retry document ingestion #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/pyai-com:pyai-com-knowledge-bases-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

pyai-com-knowledge-bases-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: PyAI Knowledge Bases API
  version: 2.14.0
  description: 'Telephony-native Voice AI behind one bearer key:


    - **Hear**, speech-to-text · `POST /v1/audio/transcriptions` (streaming + batch)

    - **Speak**, text-to-speech · `POST /v1/audio/speech`, `GET /v1/voices`

    - **Clone**, custom voices from a short clip · `/v1/voice/clones`

    - **Cast**, auto-directed expressive voiceovers · `/v1/cast`

    - **Dub**, asynchronous audio and video dubbing · `POST /v1/dub` (guide)

    - **Cue configuration frames (reserved)**; Hear streams skip knowledge-base retrieval by default

    - **Omni**, full-duplex agentic voice (speech-to-speech, grounded in your knowledge bases + tools) · `/v1/omni`

    - **Knowledge Bases**, hosted grounding for Omni: create bases, add documents (file, URL, or text), crawl a public website, bind to agents or org defaults · `/v1/knowledgebases`

    - **AMD API**, answering-machine detection: know *who or what* answered a call (human, voicemail, IVR, iPhone/Google screening, dead number) with the reason it decided · `wss …/v1/amd/stream` (Twilio Media Streams drop-in), `POST /v1/amd/config`, `GET /v1/amd/calls/{id}`

    - **Agents Beta**, the live console feature to create, configure, test, and connect Omni voice agents without code. Beta features and limits may change. ## Identity, billing and authentication

    - Before any generation or transcription, call GET /v1/me (MCP: whoami). Verify org_id, project_id, environment, scopes, limits and billing/credit context against the intended project. Do not infer identity or free usage from a key prefix or tool name. Stop on a mismatch or unknown budget; never switch to a live project automatically. - Test usage has enforced limits; live usage is billed. Current meters and rates: https://pyai.com/pricing. Agree a bounded input/request count before generating, and do not retry uncertain billable submissions blindly. Create a key in the console (it is shown once) and send it as a bearer token:


    ```

    Authorization: Bearer pyai_live_... ```


    Keys are environment-scoped: `pyai_live_...` (production) and `pyai_test_...` (sandbox). `POST /v1/sandbox/keys` creates an instant, short-lived test key without login or billing. Account signup also creates a sandbox key. Live keys consume prepaid credit; phone verification may unlock promotional credit under graduated-signup rules, but credit is not guaranteed at signup. Keys are self-validating signed tokens: they work on every PyAI surface the instant they are created, no activation or propagation delay. Treat them as opaque strings (up to 512 chars) and never parse their contents. Keep long-lived keys on trusted servers. For Omni browsers, mint an origin-locked short-lived token on your backend with POST /v1/omni/sessions; never expose a live or test API key in browser code. Offer the protocol marker and session token:


    ```

    Sec-WebSocket-Protocol: pyai.v1, pyai-key. ```


    (server-side clients may instead append `?api_key=...` to the URL). Your key is authenticated on the upgrade and never reaches the model. ## Quickstart, Hear (speech-to-text)


    ```

    curl https://api.pyai.com/v1/audio/transcriptions \

    -H "Authorization: Bearer $PYAI_API_KEY" \

    -F file=@audio.wav -F model=pyai-hear

    # -> { "text": "..." }

    ```


    ## Quickstart, Speak (text-to-speech)


    ```

    curl https://api.pyai.com/v1/audio/speech \

    -H "Authorization: Bearer $PYAI_API_KEY" \

    -H "Content-Type: application/json" \

    -d ''{"model":"pyai-speak","input":"Hello from PyAI.","voice":"voice_abc"}'' \

    --output speech.wav

    ```


    `voice` is a stock voice id from `GET /v1/voices` (the curated prebuilt catalog with personas and avatars) or a cloned voice id from `/v1/voice/clones`. Omit it to use the platform default voice (`stock_dorit_en_us`).'
  contact:
    name: PyAI
    url: https://pyai.com
servers:
- url: https://api.pyai.com
  description: Production
security:
- apiKey: []
- xApiKey: []
tags:
- name: Knowledge Bases
  description: 'Hosted knowledge bases for Omni grounding: create a base, add documents (file upload, URL fetch, or pasted text), then bind it to agent profiles or set org-wide defaults. Bound bases are retrieved per turn, no `kb_endpoint` of your own required.'
paths:
  /v1/knowledgebases:
    get:
      tags:
      - Knowledge Bases
      summary: List knowledge bases
      description: All hosted knowledge bases in your organization. Requires the `kb:manage` scope.
      operationId: listKnowledgebases
      responses:
        '200':
          description: Knowledge bases
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgebaseList'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    post:
      tags:
      - Knowledge Bases
      summary: Create a knowledge base
      description: Create a hosted knowledge base. Names are unique per organization (case-insensitive). Requires the `kb:manage` scope.
      operationId: createKnowledgebase
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - name
              properties:
                name:
                  type: string
                  maxLength: 200
                embed_model:
                  type: string
                  description: Embedding model id. Defaults to the platform standard; change only with guidance.
      responses:
        '201':
          description: Knowledge base created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Knowledgebase'
        '400':
          $ref: '#/components/responses/BadRequest'
        '409':
          description: A knowledge base with that name already exists in this organization.
  /v1/knowledgebases/default:
    get:
      tags:
      - Knowledge Bases
      summary: List org-default KB bindings
      description: The knowledge bases every Omni session in your org grounds against when its agent has no specific binding. Requires the `kb:manage` scope.
      operationId: listKnowledgebaseDefaults
      responses:
        '200':
          description: Default bindings
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbBindingList'
        '401':
          $ref: '#/components/responses/Unauthorized'
    put:
      tags:
      - Knowledge Bases
      summary: Set org-default KB bindings
      description: Replace the org-default knowledge base bindings. Omni sessions opened without an agent profile (or whose profile binds nothing) ground against these. Requires the `kb:manage` scope.
      operationId: setKnowledgebaseDefaults
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/KbBinding'
      responses:
        '200':
          description: Default bindings
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbBindingList'
        '400':
          $ref: '#/components/responses/BadRequest'
  /v1/knowledgebases/{id}:
    get:
      tags:
      - Knowledge Bases
      summary: Get a knowledge base (with documents)
      operationId: getKnowledgebase
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Knowledge base with its documents
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgebaseWithDocuments'
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      tags:
      - Knowledge Bases
      summary: Rename a knowledge base
      operationId: renameKnowledgebase
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - name
              properties:
                name:
                  type: string
                  maxLength: 200
      responses:
        '200':
          description: Updated knowledge base
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Knowledgebase'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: Name already in use in this organization.
    delete:
      tags:
      - Knowledge Bases
      summary: Delete a knowledge base
      description: Marks the knowledge base deleted; its documents and chunks are removed. Agents bound to it fall back to the org defaults. Requires the `kb:manage` scope.
      operationId: deleteKnowledgebase
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Deleted.
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/knowledgebases/{id}/documents:
    get:
      tags:
      - Knowledge Bases
      summary: List documents in a knowledge base
      operationId: listKnowledgebaseDocuments
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Documents
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbDocumentList'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
      - Knowledge Bases
      summary: Add a document (file, URL, or text)
      description: 'Three ways to add content: a multipart file upload (pdf, docx, xlsx, txt, md, csv, html, json; 25MB max), a JSON `{ "url" }` to fetch and parse, or a JSON `{ "text" }` to paste content directly. The document registers as `pending` and is chunked + embedded asynchronously; poll its `status` until `indexed`. Requires the `kb:manage` scope.'
      operationId: addKnowledgebaseDocument
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                url:
                  type: string
                  format: uri
                text:
                  type: string
                title:
                  type: string
                  maxLength: 200
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                title:
                  type: string
                  maxLength: 200
      responses:
        '202':
          description: Document registered (pending ingestion)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbDocument'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '413':
          description: File exceeds the 25MB limit.
        '415':
          description: Unsupported document type.
  /v1/knowledgebases/{id}/crawls:
    post:
      tags:
      - Knowledge Bases
      summary: Crawl a public website into a knowledge base
      description: Discover same-origin pages from a public seed URL (robots.txt / sitemap, then a shallow link walk), rank them, and register each selected page as a normal URL document. Private, loopback, and metadata addresses are rejected. Defaults to 25 pages, hard-capped at 40. Already-ingested URLs in this knowledge base are reused. Poll document `status` until `indexed` before treating the site as ready. Requires the `kb:manage` scope.
      operationId: crawlKnowledgebaseWebsite
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - url
              properties:
                url:
                  type: string
                  format: uri
                  description: Public http(s) seed URL.
                max_pages:
                  type: integer
                  minimum: 1
                  maximum: 40
                  default: 25
                  description: Page cap after ranking. Defaults to 25, never above 40.
      responses:
        '202':
          description: Pages registered (pending ingestion)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgebaseCrawl'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/knowledgebases/{id}/documents/{docId}:
    patch:
      tags:
      - Knowledge Bases
      summary: Edit a pasted-text document
      description: 'Edit in place and re-ingest. Only documents added as pasted text (`source: "api"`) can be edited; re-add files or URLs instead. Requires the `kb:manage` scope.'
      operationId: updateKnowledgebaseDocument
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      - name: docId
        in: path
        required: true
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - text
              properties:
                text:
                  type: string
                title:
                  type: string
                  maxLength: 200
      responses:
        '202':
          description: Updated and re-ingesting
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbDocument'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      tags:
      - Knowledge Bases
      summary: Remove a document
      operationId: deleteKnowledgebaseDocument
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      - name: docId
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Deleted.
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/knowledgebases/{id}/documents/{docId}/content:
    get:
      tags:
      - Knowledge Bases
      summary: Inspect a document's extracted content
      description: Returns the document, its source text (for pasted-text documents), and the first 200 indexed chunks, so you can verify what agents will retrieve. Requires the `kb:manage` scope.
      operationId: getKnowledgebaseDocumentContent
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      - name: docId
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Document content and indexed chunks
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/knowledgebases/{id}/documents/{docId}/retry:
    post:
      tags:
      - Knowledge Bases
      summary: Retry document ingestion
      description: Re-queue a `pending` or `failed` document for chunking + embedding. Requires the `kb:manage` scope.
      operationId: retryKnowledgebaseDocument
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      - name: docId
        in: path
        required: true
        schema:
          type: string
      responses:
        '202':
          description: Re-queued for ingestion
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KbDocument'
        '404':
          $ref: '#/components/responses/NotFound'
        '503':
          description: Document indexing is not configured on this deployment.
components:
  responses:
    Forbidden:
      description: 'Key lacks the required scope or the origin is not allow-listed (`code: forbidden | origin_not_allowed`)'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    BadRequest:
      description: Invalid request (bad field, unsupported value)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    NotFound:
      description: 'Resource not found (`code: not_found`)'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    Unauthorized:
      description: 'Missing or invalid API key (`code: unauthorized`)'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    KbDocument:
      type: object
      description: A knowledge base document and its ingestion state.
      properties:
        id:
          type: string
        kbId:
          type: string
        orgId:
          type: string
        source:
          type: string
          enum:
          - upload
          - url
          - api
          description: upload = file, url = fetched page, api = pasted text.
        uri:
          type:
          - string
          - 'null'
        title:
          type:
          - string
          - 'null'
        filename:
          type:
          - string
          - 'null'
        mime:
          type:
          - string
          - 'null'
        sizeBytes:
          type: integer
        chunks:
          type: integer
          description: Indexed chunk count (0 until indexed).
        status:
          type: string
          enum:
          - pending
          - indexed
          - failed
        error:
          type:
          - string
          - 'null'
          description: Human-readable failure/stall reason.
        indexedAt:
          type:
          - integer
          - 'null'
          description: Unix ms.
        createdAt:
          type: integer
          description: Unix ms.
    ErrorCode:
      type: string
      description: Stable, machine-readable error code. Branch on this rather than the human `message`.
      enum:
      - invalid_request_error
      - invalid_session_label
      - unauthorized
      - forbidden
      - origin_not_allowed
      - credit_exhausted
      - key_budget_exceeded
      - child_budget_exceeded
      - insufficient_quota
      - rate_limit_exceeded
      - concurrency_limit_exceeded
      - daily_cap_exceeded
    KnowledgebaseList:
      type: object
      properties:
        object:
          type: string
          example: list
        data:
          type: array
          items:
            $ref: '#/components/schemas/Knowledgebase'
        has_more:
          type: boolean
    KnowledgebaseWithDocuments:
      allOf:
      - $ref: '#/components/schemas/Knowledgebase'
      - type: object
        properties:
          documents:
            type: array
            items:
              $ref: '#/components/schemas/KbDocument'
    KbBindingList:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/KbBinding'
    Knowledgebase:
      type: object
      properties:
        id:
          type: string
        orgId:
          type: string
        name:
          type: string
        embedModel:
          type: string
        docCount:
          type: integer
        bytes:
          type: integer
        status:
          type: string
          enum:
          - active
          - deleted
        createdAt:
          type: integer
          description: Unix ms.
    KnowledgebaseCrawl:
      type: object
      properties:
        object:
          type: string
          example: knowledgebase.crawl
        seed_url:
          type: string
          format: uri
        max_pages:
          type: integer
        discovered:
          type: integer
          description: Same-origin candidates considered before ranking.
        accepted:
          type: integer
          description: New URL documents registered by this crawl.
        reused:
          type: integer
          description: Selected URLs that already existed in this knowledge base.
        skipped:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
              reason:
                type: string
        documents:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              url:
                type: string
                format: uri
              title:
                type: string
              reused:
                type: boolean
    KbBinding:
      type: object
      required:
      - kb_id
      properties:
        kb_id:
          type: string
          description: Knowledge base id.
        weight:
          type: number
          default: 1
          description: Retrieval weight relative to other bound bases.
    Problem:
      type: object
      description: RFC 7807 problem+json returned by the control plane (request-validation and resource errors such as 400/404/409). The stable code is the last path segment of `type`.
      required:
      - title
      - status
      properties:
        type:
          type: string
          description: Problem type URI; ends with the stable code.
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        request_id:
          type: string
    Error:
      type: object
      description: OpenAI-compatible error envelope returned by the gateway data plane (401/402/403/429). Control-plane request/resource errors use Problem (application/problem+json) instead.
      required:
      - error
      properties:
        error:
          type: object
          required:
          - message
          properties:
            message:
              type: string
              description: Human-readable explanation.
            type:
              type: string
              description: Error category, e.g. rate_limit_error.
            code:
              $ref: '#/components/schemas/ErrorCode'
            param:
              type: string
              nullable: true
              description: Offending parameter when applicable, else null.
    KbDocumentList:
      type: object
      properties:
        object:
          type: string
          example: list
        data:
          type: array
          items:
            $ref: '#/components/schemas/KbDocument'
        has_more:
          type: boolean
  securitySchemes:
    interpretationUpload:
      type: http
      scheme: bearer
      description: Short-lived write-only upload_capability returned by POST /v1/audio/interpretations/recordings. Never use it for reads.
    sessionCookie:
      type: apiKey
      in: cookie
      name: pyai_session
      description: Console session cookie. PyAI-admin routes also require the configured platform-admin email allowlist.
    apiKey:
      type: http
      scheme: bearer
      description: 'Use `Authorization: Bearer pyai_live_...` (or `pyai_test_...`).'
    xApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Header alias for bearer auth on HTTP endpoints. WebSocket auth uses the subprotocol pair `pyai.v1, pyai-key.<API_KEY>`.
x-pyai-agent-notes:
  guide: https://pyai.com/agents/speech-calling.md
  omni_frames: https://api.pyai.com/omni-frames.json
  discovery: Inspect live operation schemas; preserve IDs and required Idempotency-Key headers. SDK-first for realtime. Never infer a simulated PSTN call endpoint.