> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mka1.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Files

> Upload and list files for use across MKA1 APIs.

## Upload a file

Upload the file with `multipart/form-data`.
The live OpenAPI spec requires `file` and `purpose`.

Note: multipart file parts must include a nonblank filename. The lowercase WHATWG placeholder filename `"blob"` is treated as missing.

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  import { SDK } from '@meetkai/mka1';
  import { readFileSync } from 'node:fs';

  const sdk = new SDK({ bearerAuth: 'Bearer <mka1-api-key>' });

  const file = { fileName: 'support-manual.pdf', content: readFileSync('./support-manual.pdf') };
  const result = await sdk.llm.files.upload({
    xOnBehalfOf: '<end-user-id>', // optional — attribute the request to one of your end users
    requestBody: { file, purpose: 'assistants' },
  });
  ```

  ```ts OpenAI SDK theme={null}
  import OpenAI from 'openai';
  import fs from 'fs';

  const openai = new OpenAI({
    apiKey: '<mka1-api-key>',
    baseURL: 'https://apigw.mka1.com/api/v1/llm/',
    defaultHeaders: { 'X-On-Behalf-Of': '<end-user-id>' },
  });

  const file = await openai.files.create({
    file: fs.createReadStream('./support-manual.pdf'),
    purpose: 'assistants',
  });
  ```

  ```python Python SDK theme={null}
  from meetkai_mka1 import SDK

  sdk = SDK(bearer_auth="Bearer <mka1-api-key>")

  result = sdk.llm.files.upload(
      file={
          "file_name": "support-manual.pdf",
          "content": open("./support-manual.pdf", "rb"),
      },
      purpose="assistants",
  )
  ```

  ```csharp C# SDK theme={null}
  using MeetKai.MKA1;
  using MeetKai.MKA1.Types.Components;
  using MeetKai.MKA1.Types.Requests;

  var sdk = new SDK(bearerAuth: "Bearer <mka1-api-key>");

  var res = await sdk.Llm.Files.UploadAsync(new UploadFileRequestBody()
  {
      File = new UploadFileFile()
      {
          FileName = "support-manual.pdf",
          Content = System.IO.File.ReadAllBytes("./support-manual.pdf"),
      },
      Purpose = UploadFilePurpose.Assistants,
  });
  ```

  ```bash CLI theme={null}
  mka1 llm files upload \
    --file ./support-manual.pdf \
    --purpose assistants \
    -H 'X-On-Behalf-Of: <end-user-id>'
  ```

  ```bash Bash theme={null}
  curl https://apigw.mka1.com/api/v1/llm/files \
    --request POST \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --header 'X-On-Behalf-Of: <end-user-id>' \
    --form 'file=@./support-manual.pdf' \
    --form 'purpose=assistants'
  ```
</CodeGroup>

The response returns a `file` object with an ID such as `file-abc123`.

## List files with pagination

File listings are sorted by `created_at` (newest first by default) and return up to `limit` items per page.
When `has_more` is `true`, pass the last item's `id` as `after` to fetch the next page.

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  let after: string | undefined;
  do {
    const page = await sdk.llm.vectorStores.listFiles({
      vectorStoreId: 'vs_abc123',
      limit: 5,
      after,
      xOnBehalfOf: '<end-user-id>',
    });
    for (const vsFile of page.data) {
      console.log(vsFile.id);
    }
    after = page.hasMore ? page.lastId : undefined;
  } while (after);
  ```

  ```ts OpenAI SDK theme={null}
  // The OpenAI SDK auto-paginates: iterate and it follows the cursor for you.
  for await (const vsFile of openai.vectorStores.files.list('vs_abc123', {
    limit: 5,
  })) {
    console.log(vsFile.id);
  }
  ```

  ```python Python SDK theme={null}
  after = None
  while True:
      page = sdk.llm.vector_stores.list_files(
          vector_store_id="vs_abc123",
          limit=5,
          after=after,
      )
      for vs_file in page.data:
          print(vs_file.id)
      if not page.has_more:
          break
      after = page.last_id
  ```

  ```csharp C# SDK theme={null}
  // Listing is available via the VectorStores.ListFiles method; pass the last
  // item's id as `after` while `has_more` is true.
  // Refer to the API reference for the full method signature.
  ```

  ```bash CLI theme={null}
  mka1 llm vector-stores list-files \
    --vector-store-id vs_abc123 \
    --limit 5 \
    --after file-def456
  ```

  ```bash Bash theme={null}
  curl "https://apigw.mka1.com/api/v1/llm/vector_stores/vs_abc123/files?limit=5&after=file-def456" \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --header 'X-On-Behalf-Of: <end-user-id>'
  ```
</CodeGroup>

To page backwards, pass an item's `id` as `before` instead: the response is the page immediately preceding that item in the display order.
Files attached in the same batch can share a creation timestamp; the cursor accounts for this, so a full walk returns every file exactly once.

If a cursor's file no longer exists — for example, it was removed from the vector store while you were paging — the API returns `400 Invalid pagination cursor`. Restart the walk from the first page.

## Use uploaded files

Index documents in [Vector stores](/docs/vector-stores), provide [Document inputs](/docs/document-inputs), or prepare [evals](/docs/evals).
