> ## 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 Azure OpenAI

## Uploading Files

> [tab] 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
>     provider="@PROVIDER"   
> )
>
> upload_file_response = portkey.files.create(
>   purpose="batch",
>   file=open("file.pdf", "rb")
> )
>
> print(upload_file_response)
> ```

> [tab] 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
>     provider:"@PROVIDER"   
> });
>
> const uploadFile = async () => {
>   const file = await portkey.files.create({
>     purpose: "batch",
>     file: fs.createReadStream("file.pdf")
>   });
>
>   console.log(file);
> }
>
> await uploadFile();
>
> ```

> [tab] REST
>
> ```sh theme={"system"}
> curl --location --request POST 'https://api.portkey.ai/v1/files' \
> --header 'x-portkey-api-key: <portkey_api_key>' \
> --header 'x-portkey-provider: @provider' \
> --form 'purpose="<purpose>"' \
> --form 'file=@"<file_path>"'
> ```

> [tab] 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: "openai",
>     apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
>   })
> });
>
> const uploadFile = async () => {
>   const file = await openai.files.create({
>     purpose: "batch",
>     file: fs.createReadStream("file.pdf")
>   });
>
>   console.log(file);
> }
>
> await uploadFile();
> ```

> [tab] 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="openai",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> upload_file_response = openai.files.create(
>   purpose="batch",
>   file=open("file.pdf", "rb")
> )
>
> print(upload_file_response)
> ```

## List Files

> [tab] 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
>     provider="@PROVIDER"   
> )
>
> files = portkey.files.list()
>
> print(files)
> ```

> [tab] 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
>     provider:"@PROVIDER"   
> });
>
> const listFiles = async () => {
>   const files = await portkey.files.list();
>
>   console.log(files);
> }
>
> await listFiles();
>
> ```

> [tab] REST
>
> ```sh theme={"system"}
> curl --location 'https://api.portkey.ai/v1/files' \
> --header 'x-portkey-api-key: <portkey_api_key>' \
> --header 'x-portkey-provider: @provider'
> ```

> [tab] 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: "openai",
>     apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
>   })
> });
>
> const listFiles = async () => {
>   const files = await openai.files.list();
>
>   console.log(file);
> }
>
> await listFiles();
> ```

> [tab] 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="openai",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> files = openai.files.list()
>
> print(files)
> ```

## Get File

> [tab] 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
>     provider="@PROVIDER"   
> )
>
> file = portkey.files.retrieve(file_id="file_id")
>
> print(file)
> ```

> [tab] 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
>     provider:"@PROVIDER"   
> });
>
> const getFile = async () => {
>   const file = await portkey.files.retrieve(file_id="file_id");
>
>   console.log(file);
> }
>
> await getFile();
>
> ```

> [tab] 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-provider: @provider'
> ```

> [tab] 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: "openai",
>     apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
>   })
> });
>
> const getFile = async () => {
>   const file = await openai.files.retrieve(file_id="file_id");
>
>   console.log(file);
> }
>
> await getFile();
> ```

> [tab] 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="openai",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> file = openai.files.retrieve(file_id="file_id")
>
> print(file)
> ```

## Get File Content

> [tab] 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
>     provider="@PROVIDER"   
> )
>
> file_content = portkey.files.content(file_id="file_id")
>
> print(file_content)
> ```

> [tab] 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
>     provider:"@PROVIDER"   
> });
>
> const getFileContent = async () => {
>   const file_content = await portkey.files.content(file_id="file_id");
>
>   console.log(file_content);
> }
>
> await getFileContent();
>
> ```

> [tab] 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-provider: @provider'
> ```

> [tab] 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: "openai",
>     apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
>   })
> });
>
> const getFileContent = async () => {
>   const file_content = await openai.files.content(file_id="file_id");
>
>   console.log(file_content);
> }
>
> await getFileContent();
> ```

> [tab] 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="openai",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> file_content = openai.files.content(file_id="file_id")
>
> print(file_content)
> ```

## Delete File

> [tab] 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
>     provider="@PROVIDER"   
> )
>
> delete_file_response = portkey.files.delete(file_id="file_id")
>
> print(delete_file_response)
> ```

> [tab] 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
>     provider:"@PROVIDER"   
> });
>
> const deleteFile = async () => {
>   const delete_file_response = await portkey.files.delete(file_id="file_id");
>
>   console.log(delete_file_response);
> }
>
> await deleteFile();
>
> ```

> [tab] REST
>
> ```sh theme={"system"}
> curl --location --request DELETE 'https://api.portkey.ai/v1/files/<file_id>' \
> --header 'x-portkey-api-key: <portkey_api_key>' \
> --header 'x-portkey-provider: @provider'
> ```

> [tab] 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: "openai",
>     apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
>   })
> });
>
> const deleteFile = async () => {
>   const delete_file_response = await openai.files.delete(file_id="file_id");
>
>   console.log(delete_file_response);
> }
>
> await deleteFile();
> ```

> [tab] 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="openai",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> delete_file_response = openai.files.delete(file_id="file_id")
>
> print(delete_file_response)
> ```

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Files](https://docs.portkey.ai/docs/integrations/llms/anthropic/files.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.