Graine AI
API referenceKnowledge bases

Create a knowledge base

Create a knowledge base by uploading its first documents.

Create a knowledge base by uploading its first documents.

Send multipart/form-data with a name field and one or more files parts. The name is yours alone — another organisation using the same name does not collide with, or block, yours.

Limits. At most 10 files per request, 25MB per file and 50MB in total. Only PDF, PNG, JPG and JPEG can be read; any other type is rejected with 415 rather than accepted and silently indexed as nothing.

This request is slow. Text extraction, OCR and embedding all happen before it returns — seconds for a small PDF, minutes for a large scan. It is allowed up to 180 seconds; a 504 means the ingest was still running, so check GET /v2/knowledge-bases/{collection}/documents before retrying to avoid indexing the same file twice.

Check the response. chunks_indexed: 0 means nothing readable was found — usually a scan with no legible text. metadata_recorded: false means retrieval will work but the upload will not appear in listings. Anything of that kind is also spelled out in warnings.

Send Content-Length: an upload with no declared length is refused with 411 before any of it is read, and one larger than the total limit is refused with 413 the same way. While an upload is being indexed, further uploads from the same organisation answer 429 with Retry-After rather than queueing behind it.

Adding documents later is POST /v2/knowledge-bases/{collection}/documents. If the name already exists this returns 409; documents and knowledge bases cannot be deleted.

Rate limit: 20 requests per minute per organization (bucket knowledge.upload). Exceeding it returns 429 with Retry-After; the X-RateLimit-* response headers report your remaining allowance on every call.

POST
/v2/knowledge-bases
/v2/knowledge-bases

The Authorization access token

Authorization

Authorization
Required
Bearer <token>

Your Graine API key. Create one in the dashboard under Developers, or via POST /v2/api-keys. Send it as Authorization: Bearer <key>.

In: header

Request Body

multipart/form-dataRequired

files
Required
array<file>

The documents. Repeat the field once per file: PDF, PNG, JPG or JPEG, at most 10 files, 25MB each, 50MB per request.

name
Required
string

Name for the new knowledge base. 1-63 characters: letters, digits, dots and hyphens. Underscores are reserved.

Query Parameters

organization_idOrganization Id

Must match the organisation the API key belongs to.

Response Body

201

The created knowledge base and what was indexed into it.

collection
Required
Collection

The knowledge base the documents were added to.

retrieval_id
Required
Retrieval Id

The identifier to give an agent's rag_config.

files_accepted
Required
Files Accepted

File names that were ingested.

chunks_indexed
Required
Chunks Indexed

Text chunks created. Zero means nothing was extracted.

metadata_recorded
Required
Metadata Recorded

False when the documents were indexed but their metadata record failed to write: retrieval works, listings will not show them.

warnings
Required
Warnings

Non-fatal problems with this upload. Usually empty.

400

1000 — malformed input (bad knowledge base name, unreadable or empty file).

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

401

1100 — missing, unknown or inactive API key. 1101 — a browser session token was presented.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

403

1102 — the key is valid but lacks the scope this endpoint requires, or names another organisation. GET /v2/scopes reports which scopes the key holds.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

409

1201 — that knowledge base name is not available, or it already exists.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

411

1000 — an upload arrived without Content-Length. Chunked uploads are not accepted.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

413

1000 — the upload exceeds the per-file or per-request size limit.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

415

1000 — a file is not a PDF, PNG, JPG or JPEG.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

422

1001 — the body or query failed validation; the message names the first offending field.

error
Required
integer

Stable integer code from the error table. Branch on this, not on the message.

message
Required
string

One human-readable sentence. Wording may change; the code will not.

429

1300 — per-organisation rate limit exceeded. Carries Retry-After.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

503

1501 — the knowledge service is unreachable or returned a 5xx.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

504

1502 — the knowledge service did not respond in time. A slow ingest may still complete.

error
Required
Error

Stable integer code from the /v2 error table. Branch on this.

message
Required
Message

One human-readable sentence. Wording may change; the code will not.

curl -X POST "https://api.graine.ai/v2/knowledge-bases?organization_id=string" \
  -H "Authorization: Bearer <token>" \
  -F files="[\n  \"string\"\n]" \
  -F name="handbook"

The created knowledge base and what was indexed into it.

{
  "collection": "product-handbook",
  "retrieval_id": "internal_organization-live-EXAMPLE__product-handbook",
  "files_accepted": [
    "pricing-2026.pdf"
  ],
  "chunks_indexed": 84,
  "metadata_recorded": true,
  "warnings": []
}