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

# Files

> Upload files to Fireworks

## Uploading Files

<Tabs>
  <Tab title="Python">
    ```python theme={"system"}
    from portkey_ai import Portkey

    # Initialize the Portkey client
    portkey = Portkey(
        api_key="PORTKEY_API_KEY",  # Replace with your Portkey API key
        virtual_key="VIRTUAL_KEY",   # Add your provider's virtual key
        provider="fireworks-ai",
        fireworks_account_id="FIREWORKS_ACCOUNT_ID"
    )

    upload_file_response = portkey.files.create(
      purpose="batch",
      file=open("file.pdf", "rb")
    )

    print(upload_file_response)
    ```
  </Tab>

  <Tab title="NodeJS">
    ```js theme={"system"}
    import { Portkey } from 'portkey-ai';

    // Initialize the Portkey client
    const portkey = new Portkey({
        apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
        virtualKey: "VIRTUAL_KEY",   // Add your provider's virtual key
        provider: "fireworks-ai",
        fireworksAccountId: "FIREWORKS_ACCOUNT_ID"
    });

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

      console.log(file);
    }

    await uploadFile();

    ```
  </Tab>

  <Tab title="REST">
    ```sh theme={"system"}
    # you can also use a virtual key here
    curl --location 'https://api.portkey.ai/v1/files' \
    --header 'x-portkey-api-key: <portkey_api_key>' \
    --header 'x-portkey-provider: fireworks-ai' \
    --header 'Content-Type: application/json' \
    --header 'x-portkey-fireworks-account-id: {YOUR_FIREWORKS_ACCOUNT_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
    import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

    const openai = new OpenAI({
      apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
      baseURL: PORTKEY_GATEWAY_URL,
      defaultHeaders: createHeaders({
        provider: "fireworks-ai",
        apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
        fireworksAccountId: "FIREWORKS_ACCOUNT_ID"
      })
    });

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

      console.log(file);
    }

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

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

    openai = OpenAI(
        api_key='OPENAI_API_KEY',
        base_url=PORTKEY_GATEWAY_URL,
        default_headers=createHeaders(
            provider="fireworks-ai",
            api_key="PORTKEY_API_KEY",
            fireworks_account_id="FIREWORKS_ACCOUNT_ID"
        )
    )

    upload_file_response = openai.files.create(
      purpose="batch",
      file=open("file.pdf", "rb")
    )

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

## Get File

<Tabs>
  <Tab title="Python">
    ```python theme={"system"}
    from portkey_ai import Portkey

    # Initialize the Portkey client
    portkey = Portkey(
        api_key="PORTKEY_API_KEY",  # Replace with your Portkey API key
        virtual_key="VIRTUAL_KEY",   # Add your provider's virtual key
        fireworks_account_id="FIREWORKS_ACCOUNT_ID"
    )

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

    print(file)
    ```
  </Tab>

  <Tab title="NodeJS">
    ```js theme={"system"}
    import { Portkey } from 'portkey-ai';

    // Initialize the Portkey client
    const portkey = new Portkey({
        apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
        virtualKey: "VIRTUAL_KEY",   // Add your provider's virtual key
        fireworksAccountId="FIREWORKS_ACCOUNT_ID",
    });

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

      console.log(file);
    }

    await getFile();

    ```
  </Tab>

  <Tab title="REST">
    ```sh theme={"system"}
    curl --location 'https://api.portkey.ai/v1/files/<file_id>' \
    --header 'x-portkey-api-key: <portkey_api_key>' \
    --header 'x-portkey-virtual-key: <virtual_key>' \
    --header 'x-portkey-fireworks-account-id: {YOUR_FIREWORKS_ACCOUNT_ID}'
    ```
  </Tab>

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

    const openai = new OpenAI({
      apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
      baseURL: PORTKEY_GATEWAY_URL,
      defaultHeaders: createHeaders({
        provider: "fireworks-ai",
        apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
        fireworksAccountId="FIREWORKS_ACCOUNT_ID",
      })
    });

    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
    from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

    openai = OpenAI(
        api_key='OPENAI_API_KEY',
        base_url=PORTKEY_GATEWAY_URL,
        default_headers=createHeaders(
            provider="fireworks-ai",
            api_key="PORTKEY_API_KEY",
            fireworks_account_id="FIREWORKS_ACCOUNT_ID",
        )
    )

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

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

## Get File Content

<Tabs>
  <Tab title="Python">
    ```python theme={"system"}
    from portkey_ai import Portkey

    # Initialize the Portkey client
    portkey = Portkey(
        api_key="PORTKEY_API_KEY",  # Replace with your Portkey API key
        virtual_key="VIRTUAL_KEY",   # Add your provider's virtual key
        fireworks_account_id="FIREWORKS_ACCOUNT_ID",
    )

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

    print(file_content)
    ```
  </Tab>

  <Tab title="NodeJS">
    ```js theme={"system"}
    import { Portkey } from 'portkey-ai';

    // Initialize the Portkey client
    const portkey = new Portkey({
        apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
        virtualKey: "VIRTUAL_KEY",   // Add your provider's virtual key
        fireworksAccountId="FIREWORKS_ACCOUNT_ID",
    });

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

      console.log(file_content);
    }

    await getFileContent();

    ```
  </Tab>

  <Tab title="REST">
    ```sh theme={"system"}
    curl --location 'https://api.portkey.ai/v1/files/<file_id>/content' \
    --header 'x-portkey-api-key: <portkey_api_key>' \
    --header 'x-portkey-virtual-key: <virtual_key>' \
    --header 'x-portkey-fireworks-account-id: {YOUR_FIREWORKS_ACCOUNT_ID}'
    ```
  </Tab>

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

    const openai = new OpenAI({
      apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
      baseURL: PORTKEY_GATEWAY_URL,
      defaultHeaders: createHeaders({
        provider: "fireworks-ai",
        apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
        fireworksAccountId="FIREWORKS_ACCOUNT_ID",
      })
    });

    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
    from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

    openai = OpenAI(
        api_key='OPENAI_API_KEY',
        base_url=PORTKEY_GATEWAY_URL,
        default_headers=createHeaders(
            provider="fireworks-ai",
            api_key="PORTKEY_API_KEY",
            fireworks_account_id="FIREWORKS_ACCOUNT_ID",
        )
    )

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

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

* [Fireworks Datasets API](https://docs.fireworks.ai/api-reference/list-datasets)
