> ## 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 Google Cloud Storage for Vertex AI fine-tuning and batch inference

To perform fine-tuning or batch inference with Vertex AI, you need to upload files to Google Cloud Storage.
With Portkey, you can easily upload files to GCS and use them for fine-tuning or batch inference with Vertex AI models.

## 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="@VERTEX_PROVIDER",   
>     vertex_storage_bucket_name="your_bucket_name", # Specify the GCS bucket name
>     provider_file_name="your_file_name.jsonl", # Specify the file name in GCS
>     provider_model="gemini-1.5-flash-001" # Specify the model to use
> )
>
> upload_file_response = portkey.files.create(
>   purpose="fine-tune", # Can be "fine-tune" or "batch"
>   file=open("dataset.jsonl", "rb")
> )
>
> print(upload_file_response)
> ```

> [tab] NodeJS
>
> ```js theme={"system"}
> import { Portkey } from 'portkey-ai';
> import * as fs from 'fs';
>
> // Initialize the Portkey client
> const portkey = Portkey({
>     apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
>     provider:"@VERTEX_PROVIDER",   
>     vertexStorageBucketName: "your_bucket_name", // Specify the GCS bucket name
>     providerFileName: "your_file_name.jsonl", // Specify the file name in GCS
>     providerModel: "gemini-1.5-flash-001" // Specify the model to use
> });
>
> const uploadFile = async () => {
>   const file = await portkey.files.create({
>     purpose: "fine-tune", // Can be "fine-tune" or "batch"
>     file: fs.createReadStream("dataset.jsonl")
>   });
>
>   console.log(file);
> }
>
> uploadFile();
> ```

> [tab] REST
>
> ```sh theme={"system"}
> curl -X POST --header 'x-portkey-api-key: <portkey_api_key>' \
>  --header 'x-portkey-provider: @your-vertex-provider' \
>  --header 'x-portkey-vertex-storage-bucket-name: <bucket_name>' \
>  --header 'x-portkey-provider-file-name: <file_name>.jsonl' \
>  --header 'x-portkey-provider-model: <model_name>' \
>  --form 'purpose="fine-tune"' \
>  --form 'file=@dataset.jsonl' \
>  'https://api.portkey.ai/v1/files'
> ```

> [tab] OpenAI NodeJS
>
> ```js theme={"system"}
> import OpenAI from 'openai';
> import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
> import * as fs from 'fs';
>
> const openai = new OpenAI({
>   apiKey: 'OPENAI_API_KEY',
>   baseURL: PORTKEY_GATEWAY_URL,
>   defaultHeaders: createHeaders({
>     provider:"@VERTEX_PROVIDER",
>     apiKey: "PORTKEY_API_KEY",
>     vertexStorageBucketName: "your_bucket_name",
>     providerFileName: "your_file_name.jsonl",
>     providerModel: "gemini-1.5-flash-001"
>   })
> });
>
> const uploadFile = async () => {
>   const file = await openai.files.create({
>     purpose: "fine-tune", // Can be "fine-tune" or "batch"
>     file: fs.createReadStream("dataset.jsonl")
>   });
>
>   console.log(file);
> }
>
> 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="@VERTEX_PROVIDER",
>         api_key="PORTKEY_API_KEY",
>         vertex_storage_bucket_name="your_bucket_name",
>         provider_file_name="your_file_name.jsonl",
>         provider_model="gemini-1.5-flash-001"
>     )
> )
>
> upload_file_response = openai.files.create(
>   purpose="fine-tune", # Can be "fine-tune" or "batch"
>   file=open("dataset.jsonl", "rb")
> )
>
> print(upload_file_response)
> ```

## 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="@VERTEX_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 = Portkey({
>     apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
>     provider:"@VERTEX_PROVIDER"   
> });
>
> const getFile = async () => {
>   const file = await portkey.files.retrieve("file_id");
>
>   console.log(file);
> }
>
> getFile();
> ```

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

> [tab] OpenAI NodeJS
>
> ```js theme={"system"}
> import OpenAI from 'openai';
> import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
>
> const openai = new OpenAI({
>   apiKey: 'OPENAI_API_KEY',
>   baseURL: PORTKEY_GATEWAY_URL,
>   defaultHeaders: createHeaders({
>     provider:"@VERTEX_PROVIDER",
>     apiKey: "PORTKEY_API_KEY"
>   })
> });
>
> const getFile = async () => {
>   const file = await openai.files.retrieve("file_id");
>
>   console.log(file);
> }
>
> 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="@VERTEX_PROVIDER",
>         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="@VERTEX_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 = Portkey({
>     apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
>     provider:"@VERTEX_PROVIDER"   
> });
>
> const getFileContent = async () => {
>   const fileContent = await portkey.files.content("file_id");
>
>   console.log(fileContent);
> }
>
> getFileContent();
> ```

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

> [tab] OpenAI NodeJS
>
> ```js theme={"system"}
> import OpenAI from 'openai';
> import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai';
>
> const openai = new OpenAI({
>   apiKey: 'OPENAI_API_KEY',
>   baseURL: PORTKEY_GATEWAY_URL,
>   defaultHeaders: createHeaders({
>     provider:"@VERTEX_PROVIDER",
>     apiKey: "PORTKEY_API_KEY"
>   })
> });
>
> const getFileContent = async () => {
>   const fileContent = await openai.files.content("file_id");
>
>   console.log(fileContent);
> }
>
> 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="@VERTEX_PROVIDER",
>         api_key="PORTKEY_API_KEY"
>     )
> )
>
> file_content = openai.files.content(file_id="file_id")
>
> print(file_content)
> ```

Note: The `ListFiles` endpoint is not supported for Vertex AI.

***

> [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.