Document: Upload v1
The upload
document API endpoint allows you to upload documents to a memory in Langbase with API. This endpoint requires a User or Org API key.
This endpoint can also be used to replace an existing document in a memory. To do this, you need to provide the same documentName
and memoryName
attributes as the existing document. We also have a separate guide on how to replace an existing document in memory.
Generate a User/Org API key
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
Step #1Get SignedUrl to Upload Document
Uploading a document to a memory requires a signed URL. POST
a request to this endpoint to get a signed URL and use PUT
method to upload the document.
Headers
- Name
Content-Type
- Type
- string
- Required
- Required
- Description
Request content type. Needs to be
application/json
.
- Name
Authorization
- Type
- string
- Required
- Required
- Description
Replace
<YOUR_API_KEY>
with your user/org API key.
Body Parameters
- Name
memoryName
- Type
- string
- Required
- Required
- Description
Name of the memory to which the document will be uploaded.
- Name
documentName
- Type
- string
- Required
- Required
- Description
Name of the document.
Optional attributes
- Name
meta
- Type
- object
- Description
Custom metadata for the document, limited to string key-value pairs. A maximum of 10 pairs is allowed.
Deprecated attributes
- Name
fileName
- Type
- string
- Description
Name of the document.
curl https://api.langbase.com/v1/memory/documents \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-d '{
"memoryName": "rag-memory",
"documentName": "test-document.pdf",
"meta": {
"category": "technical",
"section": "overview"
}
}'
Response
- Name
Response
- Type
- object
- Description
The response object returned by the API endpoint.
Response
interface Response { signedUrl: string; }
- Name
signedUrl
- Type
- string
- Description
Signed URL that can be used to upload a document.
API Response
{
"signedUrl": "https://b.langbase.com/..."
}
Step #2Upload Document on SignedUrl
Use the signed URL to upload the document to the memory. The signed URL is valid for 2 hours.
Headers
- Name
Content-Type
- Type
- string
- Required
- Required
- Description
Request content type. Needs to be the MIME type of the document. Currently, we support
application/pdf
,text/plain
,text/markdown
,text/csv
, and all major code files astext/plain
. For csv, pdf, text, and markdown files, it should correspond to the file type used in thedocumentName
attribute in step 1. For code files, it should betext/plain
.
Body Parameters
- Name
body
- Type
- FileBody
- Required
- Required
- Description
The body of the file to be stored in the bucket. It can be
Buffer
,File
,FormData
, orReadableStream
type.
Usage example
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
Upload Document
curl -X PUT \
-H 'Content-Type: application/pdf' \
--data-binary "@path/to/pdfFile" \
"{SignedUrl}"
Response
- Name
Response
- Type
- object
- Description
The response object returned by the API endpoint.
Response
interface Response { ok: boolean; status: number; statusText: string; }
- Name
ok
- Type
- boolean
- Description
Indicates whether the upload was successful.
- Name
status
- Type
- number
- Description
HTTP status code of the upload response.
- Name
statusText
- Type
- string
- Description
HTTP status message corresponding to the status code.
API Response
{
"ok": true,
"status": 200,
"statusText": "OK"
}