Document API: Upload beta

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 fileName and memoryName attributes as the existing document. We also have a separate guide on how to replace an existing document in memory.


Deprecation Notice

This API endpoint has been deprecated. Please use the new upload document API endpoint.


You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.


Deprecated/beta/org/{org}/memorysets/documents

Step #1

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.

Required headers

  • Name
    Content-Type
    Type
    string
    Description

    Request content type. Needs to be application/json.

  • Name
    Authorization
    Type
    string
    Description

    Replace <ORG_API_KEY> with your organization API key.

Required path parameters

  • Name
    org
    Type
    string
    Description

    The organization username.

    Replace {org} with the organization username.

Required attributes

  • Name
    memoryName
    Type
    string
    Description

    Name of the memory to which the document will be uploaded.

  • Name
    ownerLogin
    Type
    string
    Description

    It is the username of the org. It is returned in Memory List endpoint as well as owner_login.

  • Name
    fileName
    Type
    string
    Description

    Name of the document.

Once you have the signed URL, you can upload the document using the PUT method.

PUT{SignedUrl}

Step #2

Use the signed URL to upload the document to the memory. The signed URL is valid for 2 hours.

Required headers

  • Name
    Content-Type
    Type
    string
    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 as text/plain. For csv, pdf, text, and markdown files, it should correspond to the file type used in the fileName attribute in step 1. For code files, it should be text/plain.

Required attributes

  • Name
    body
    Type
    FileBody
    Description

    The body of the file to be stored in the bucket. It can be Buffer, File, FormData, or ReadableStream type.

POST
/beta/org/{org}/memorysets/documents
curl https://api.langbase.com/beta/org/{org}/memorysets/documents \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer <ORG_API_KEY>" \ -d '{ "memoryName": "rag-memory", "ownerLogin": "langbase", "fileName": "file.pdf" }'

Response

{ "signedUrl": "https://b.langbase.com/..." }

PUT
{SignedUrl}
curl -X PUT \ -H 'Content-Type: application/pdf' \ --data-binary "@path/to/pdfFile" \ "{SignedUrl}"

Response

{ // ... "status": 200, "statusText": 'OK', // ... }

Deprecated/beta/user/memorysets/documents

Step #1

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.

Required headers

  • Name
    Content-Type
    Type
    string
    Description

    Request content type. Needs to be application/json.

  • Name
    Authorization
    Type
    string
    Description

    Replace USER_API_KEY with your User API key.

Required attributes

  • Name
    memoryName
    Type
    string
    Description

    Name of the memory to which the document will be uploaded.

  • Name
    ownerLogin
    Type
    string
    Description

    It is the username of the org/user. It is returned in Memory List endpoint as well as owner_login.

  • Name
    fileName
    Type
    string
    Description

    Name of the document.

Once you have the signed URL, you can upload the document using the PUT method.

PUT{SignedUrl}

Step #2

Use the signed URL to upload the document to the memory. The signed URL is valid for 2 hours.

Required headers

  • Name
    Content-Type
    Type
    string
    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 as text/plain. For csv, pdf, text, and markdown files, it should correspond to the file type used in the fileName attribute in step 1. For code files, it should be text/plain.

Required attributes

  • Name
    body
    Type
    FileBody
    Description

    The body of the file to be stored in the bucket. It can be Buffer, File, FormData, or ReadableStream type.

POST
/beta/user/memorysets/documents
curl https://api.langbase.com/beta/user/memorysets/documents \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer <USER_API_KEY>" \ -d '{ "memoryName": "rag-memory", "ownerLogin": "langbase", "fileName": "file.pdf" }'

Response

{ "signedUrl": "https://b.langbase.com/..." }

PUT
{SignedUrl}
curl -X PUT \ -H 'Content-Type: application/pdf' \ --data-binary "@path/to/pdfFile" \ "{SignedUrl}"

Response

{ // ... "status": 200, "statusText": 'OK', // ... }