> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/stackai-api/knowledge-bases-v1/lifecycle-resources-and-sync/post-v1-knowledge-bases-knowledge_base_id-resources.md).

# POST /v1/knowledge-bases/{knowledge\_base\_id}/resources

## Create Resource

> Upload a file directly to a knowledge base and start indexing.\
> \
> This endpoint allows API users to upload files directly without needing to use\
> presigned URLs. The file is uploaded to storage and indexing is started automatically.\
> Returns the resource ID so callers can poll for indexing status.\
> \
> \*\*How to use\*\*\
> \
> Upload multipart field file (singular). Indexing starts automatically. Save the resource\_id from the 202 response and poll resource GET until indexed or error. Do not set the multipart boundary yourself or re-upload while waiting.\
> \
> \*\*Authentication and permissions\*\*\
> \
> Required permissions: \`kbs.index\`. Resource and owner access checks also apply.

```json
{"openapi":"3.1.0","info":{"title":"StackAI API","version":"0.1.0"},"tags":[{"name":"endpoint-uploadKnowledgeBaseResource"}],"servers":[{"url":"https://api.stack-ai.com","description":"Hosted API. Use your deployment-specific origin for private installations."}],"security":[{"HTTPBearer":[]}],"components":{"securitySchemes":{"HTTPBearer":{"type":"http","scheme":"bearer","description":"Personal API key (sk_...) or supported user access JWT. See Authentication and authorization for endpoint restrictions and scopes. Use exactly one Authorization header."}},"schemas":{"Body_uploadKnowledgeBaseResource":{"properties":{"file":{"type":"string","format":"binary","title":"File","description":"The file to upload to the knowledge base"}},"type":"object","required":["file"],"title":"Body_uploadKnowledgeBaseResource"},"ResourceUploadResponse":{"properties":{"message":{"type":"string","title":"Message"},"resource_id":{"type":"string","format":"uuid","title":"Resource Id"}},"type":"object","required":["message","resource_id"],"title":"ResourceUploadResponse","description":"Result of a file upload, including the resource ID for status polling."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/knowledge-bases/{knowledge_base_id}/resources":{"post":{"tags":["endpoint-uploadKnowledgeBaseResource"],"summary":"Create Resource","description":"Upload a file directly to a knowledge base and start indexing.\n\nThis endpoint allows API users to upload files directly without needing to use\npresigned URLs. The file is uploaded to storage and indexing is started automatically.\nReturns the resource ID so callers can poll for indexing status.\n\n**How to use**\n\nUpload multipart field file (singular). Indexing starts automatically. Save the resource_id from the 202 response and poll resource GET until indexed or error. Do not set the multipart boundary yourself or re-upload while waiting.\n\n**Authentication and permissions**\n\nRequired permissions: `kbs.index`. Resource and owner access checks also apply.","operationId":"uploadKnowledgeBaseResource","parameters":[{"name":"knowledge_base_id","in":"path","required":true,"schema":{"type":"string","format":"uuid","title":"Knowledge Base Id"}}],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/Body_uploadKnowledgeBaseResource"}}}},"responses":{"202":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResourceUploadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/stackai-api/knowledge-bases-v1/lifecycle-resources-and-sync/post-v1-knowledge-bases-knowledge_base_id-resources.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
