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

# Files

> Upload files to S3 for Bedrock batch inference

To perform batch inference with Bedrock, you need to upload files to S3.
This process can be cumbersome and duplicative in nature because you need to transform your data into model specific formats.

With Prisma AIRS AI Gateway, you can upload the file in [OpenAI format](https://platform.openai.com/docs/guides/batch#1-preparing-your-batch-file) and the AI Gateway will handle transforming the file into the format required by Bedrock on the fly!

This is the most efficient way to

* Test your data with different foundation models
* Perform A/B testing with different foundation models
* Perform batch inference with different foundation models

## Uploading Files

<Tabs>
  <Tab title="REST">
    ```sh theme={"system"}
    # you can also use a provider from Model Catalog here
    curl --location 'https://aigw.portkey.ai/v1/files' \
    --header 'Authorization: Bearer <portkey_api_key>' \
    --header 'x-portkey-provider: bedrock' \
    --header 'Content-Type: application/json' \
    --header 'x-portkey-aws-access-key-id: {YOUR_AWS_ACCESS_KEY_ID}' \
    --header 'x-portkey-aws-secret-access-key: {YOUR_AWS_SECRET_ACCESS_KEY}' \
    --header 'x-portkey-aws-region: {YOUR_AWS_REGION}' \
    --header 'x-portkey-aws-s3-bucket: {YOUR_AWS_S3_BUCKET}' \
    --header 'x-portkey-aws-s3-object-key: {YOUR_AWS_S3_OBJECT_KEY}' \
    --header 'x-portkey-aws-bedrock-model: {YOUR_AWS_BEDROCK_MODEL}' \
    --header 'x-portkey-amz-server-side-encryption: {ENCRYPTION_TYPE}' \
    --header 'x-portkey-amz-server-side-encryption-aws-kms-key-id: {KMS_KEY_ID}' \
    --form 'file=@"{YOUR_FILE_PATH}"',
    --form 'purpose="batch"'
    ```
  </Tab>

  <Tab title="OpenAI NodeJS">
    ```js theme={"system"}
    import OpenAI from 'openai'; // We're using the v4 SDK

    const openai = new OpenAI({
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: {
        "x-portkey-provider": "openai",
        "x-portkey-aws-region": "YOUR_AWS_REGION",
        "x-portkey-aws-s3-bucket": "YOUR_AWS_S3_BUCKET",
        "x-portkey-aws-s3-object-key": "YOUR_AWS_S3_OBJECT_KEY",
        "x-portkey-aws-bedrock-model": "YOUR_AWS_BEDROCK_MODEL",
        "x-portkey-amz-server-side-encryption": "ENCRYPTION_TYPE", // [optional] default is aws:kms
        "x-portkey-amz-server-side-encryption-aws-kms-key-id": "KMS_KEY_ID" // [optional] only if encrypting the file at rest with a KMS key
      }
    });

    const uploadFile = async () => {
      const file = await openai.files.create({
        purpose: "batch",
        file: fs.createReadStream("file.pdf")
      });

      console.log(file);
    }

    await uploadFile();
    ```
  </Tab>
</Tabs>

## Get File

<Tabs>
  <Tab title="REST">
    ```sh theme={"system"}
    curl --location 'https://aigw.portkey.ai/v1/files/<file_id>' \
    --header 'Authorization: Bearer <portkey_api_key>' \
    --header 'x-portkey-provider: @provider' \
    --header 'x-portkey-aws-region: <aws_region>'
    ```
  </Tab>

  <Tab title="OpenAI NodeJS">
    ```js theme={"system"}
    import OpenAI from 'openai'; // We're using the v4 SDK

    const openai = new OpenAI({
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["OPENAI_API_KEY"],
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: {
          "x-portkey-provider": "openai",
          // defaults to process.env["PORTKEY_API_KEY"]
          "x-portkey-aws-region": "YOUR_AWS_REGION",
      }
    });

    const getFile = async () => {
      const file = await openai.files.retrieve(file_id="file_id");

      console.log(file);
    }

    await getFile();
    ```
  </Tab>

  <Tab title="OpenAI Python">
    ```python theme={"system"}
    from openai import OpenAI

    openai = OpenAI(
        api_key="PORTKEY_API_KEY",
        base_url="https://aigw.portkey.ai/v1",
        default_headers={"x-portkey-provider": "openai", "x-portkey-aws-region": "YOUR_AWS_REGION"}
    )

    file = openai.files.retrieve(file_id="file_id")

    print(file)
    ```
  </Tab>
</Tabs>

## Get File Content

<Tabs>
  <Tab title="REST">
    ```sh theme={"system"}
    curl --location 'https://aigw.portkey.ai/v1/files/<file_id>/content' \
    --header 'Authorization: Bearer <portkey_api_key>' \
    --header 'x-portkey-provider: @provider' \
    --header 'x-portkey-aws-region: <aws_region>'
    ```
  </Tab>

  <Tab title="OpenAI NodeJS">
    ```js theme={"system"}
    import OpenAI from 'openai'; // We're using the v4 SDK

    const openai = new OpenAI({
      apiKey: "PORTKEY_API_KEY", // defaults to process.env["OPENAI_API_KEY"],
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: {
          "x-portkey-provider": "openai",
          // defaults to process.env["PORTKEY_API_KEY"]
          "x-portkey-aws-region": "YOUR_AWS_REGION",
      }
    });

    const getFileContent = async () => {
      const file_content = await openai.files.content(file_id="file_id");

      console.log(file_content);
    }

    await getFileContent();
    ```
  </Tab>

  <Tab title="OpenAI Python">
    ```python theme={"system"}
    from openai import OpenAI

    openai = OpenAI(
        api_key="PORTKEY_API_KEY",
        base_url="https://aigw.portkey.ai/v1",
        default_headers={"x-portkey-provider": "openai", "x-portkey-aws-region": "YOUR_AWS_REGION"}
    )

    file_content = openai.files.content(file_id="file_id")

    print(file_content)
    ```
  </Tab>
</Tabs>

<Note>
  The following endpoints are **NOT** supported for Bedrock for security reasons:

  * `GET /v1/files`
  * `DELETE /v1/files/{file_id}`
</Note>


## Related topics

- [Files](/docs/aigw/integrations/llms/anthropic/files.md)
