Skip to Content

Analyze files using OpenAI file inputs in Jitterbit Studio

Introduction

OpenAI's Chat Completions API supports sending file content directly in a message using file inputs: the file is base64-encoded and embedded in the message as a file content item with a data URI (data:<media-type>;base64,<content>). No separate upload to the Files API is required.

For plain-text files such as CSV, a simpler alternative is to decode the base64 content to a readable string and embed it directly in the prompt. When combined with OpenAI's code interpreter (available through the Responses API), this lets the model parse and query the file contents programmatically.

Both patterns call the OpenAI API directly using an HTTP v2 activity, which provides full control over the request body structure that each approach requires.

This guide covers both patterns, starting from the same step: downloading a file from an external API whose response body contains the file content as base64-encoded data.

Design pattern

Each approach follows the transformation pattern:

flowchart LR A["HTTP v2
Download file
(GET)"] --> B["Transformation
Extract base64
content"] --> C["Script
Decode or prepare
file content"] --> D["Transformation
Build OpenAI
request"] --> E["HTTP v2
OpenAI call
(POST)"] --> F["Transformation
Extract AI
response"]

The GET activity downloads the file and the first transformation extracts its base64-encoded content into a variable. A script then either decodes the content (for text files) or prepares it as a data URI (for binary files). The second transformation builds the OpenAI request body, the POST activity sends it, and the final transformation extracts the model's reply.

Part 1: Download the file and extract the base64 content

Many APIs return file content as a base64-encoded string in the JSON response body. This part covers fetching that content and storing it for use in later steps.

Configure the HTTP v2 connection and GET activity

For HTTP v2 connection setup and authentication, see Call a REST API using the HTTP v2 connector.

Configure an HTTP v2 GET activity that fetches the file from the source API. Set the URL path to the file download endpoint, using a project variable to pass the file ID dynamically if needed.

Extract the base64 content

Add a transformation after the GET activity. Map the JSON path that holds the base64 string to a script node that stores it in a variable:

<trans>
$core.base64fileContent = json$response$responseItem$responseContent$;
</trans>

Replace the JSON path above with the actual path from your API's response schema. The variable name core.base64fileContent is used in the steps that follow.

Part 2: Analyze a text file by decoding and embedding its content

For CSV and other plain-text files, decode the base64 content to a readable string and embed it in the user message. The model sees the file content as part of the prompt.

Decode the base64 content

Add a script step after the extraction transformation. Apply Base64Decode, BinaryToHex, and HexToString in sequence to convert the base64 string to readable text:

$decodedFileContent = HexToString(BinaryToHex(Base64Decode($core.base64fileContent)));

The three-function chain is required because Base64Decode returns binary data, BinaryToHex converts it to a hex string, and HexToString converts the hex string to readable text. Skipping BinaryToHex produces a hex-encoded string rather than the original text content.

Build the prompt

Construct the prompt by embedding the decoded content inline. For CSV parsing, instruct the model to treat the content as RFC 4180 and specify exactly what to return:

$gpt_userPrompt = "Role: " + $newHire_jobTitle + ".\n"
    + "Below is CSV text. Use Python to parse it as RFC 4180.\n"
    + "Rules:\n"
    + "- First row contains headers.\n"
    + "- Return ONLY rows where the target column value is exactly 'Yes'.\n"
    + "- Return the matching values as a single comma-separated line.\n\n"
    + "CSV START\n"
    + $decodedFileContent + "\n"
    + "CSV END";

Adjust the instructions for your own file structure and analysis goal.

Configure the Responses API request transformation

For structured data parsing, use the Responses API (v1/responses) with the code interpreter tool enabled. The code interpreter gives the model a Python execution environment to parse the CSV programmatically rather than relying on pattern matching.

Add a transformation that maps the request body. The Responses API request schema differs from Chat Completions: the message field is input, not messages.

Target path Script
json/model $gpt.model
json/input/item/role "user"
json/input/item/content $gpt_userPrompt

To enable the code interpreter, add [{"type":"code_interpreter"}] to the tools array in the request body. This can be done in a script before the transformation by building the full request body as a JSON string, or by adding a json/tools/item/type mapping with the value "code_interpreter".

In the script step before this transformation, set the URL path for the Responses endpoint:

$openAi.url.path = "v1/responses";

Read the response

After the POST activity, add a transformation to extract the model's reply. For the Responses API, the output text is in json$output$item.content$item.text$:

<trans>
$llm_response = json$output$item.content$item.text$;
</trans>

Part 3: Analyze a binary file using inline file data

For PDFs and other binary files, keep the base64 content as-is and embed it in the message content array using a data URI. The model receives the full file alongside the text prompt.

Prepare the prompt and content variable

Add a script step to set the user prompt and assign the base64 content to the variable that the request transformation will use:

$gpt_userPrompt_fileInputs = "Please analyze the attached document and provide a concise "
    + "summary of the candidate's professional background, key skills, and notable "
    + "achievements.";
$offerSigned_cv_base64 = $core.base64fileContent;

Do not decode the base64 content at this step. The Chat Completions API expects the raw base64 string as part of the data URI.

Configure the Chat Completions request transformation

Add a transformation that maps the request body. The content field is an array with two items: a text item for the prompt and a file item for the document.

Target path Script
json/model $gpt.model
json/messages/item/role "user"
json/messages/item/content/item/type "text"
json/messages/item/content/item/text $gpt_userPrompt_fileInputs
json/messages/item/content/item#1/type "file"
json/messages/item/content/item#1/file/filename "document.pdf"
json/messages/item/content/item#1/file/file_data "data:application/pdf;base64," + $offerSigned_cv_base64

The item#1 notation creates a second element in the content array. The file_data value must be a complete data URI, not the raw base64 string. Use application/pdf as the MIME type for PDF files.

Note

Inline file data is supported for PDF and image formats. For an up-to-date list of supported file types, see the OpenAI file inputs documentation.

In the script step before this transformation, set the URL path to the Chat Completions endpoint:

$openAi.url.path = "v1/chat/completions";

Configure the HTTP v2 POST activity to OpenAI

Configure an HTTP v2 POST activity for the OpenAI API. If you already have an OpenAI connection from another operation, reuse it. Otherwise, create a new connection:

  1. Set Base URL to https://api.openai.com, or reference a project variable.

  2. Add a Bearer authorization header using a project variable that holds your OpenAI API key (with its value hidden):

    Authorization: Bearer [openai_api_key]
    
  3. Set the URL Path to [openAi.url.path] so that the operation can switch between endpoints using the script variable.

  4. Set Request Format and Response Format to JSON.

For detailed connection and authentication steps, see Call a REST API using the HTTP v2 connector.

Read the response

Add a transformation after the POST activity to extract the model's reply. For the Chat Completions API, the generated text is in json$choices$item.message$content$:

<trans>
$offerSigned_cvSummary = json$choices$item.message$content$;
</trans>

Verify the integration

  1. Deploy and run the operation manually.

  2. In the operation logs, confirm that the GET activity returned a successful response and that the POST activity to OpenAI also completed without errors.

  3. Inspect the log output to confirm that the response variable (llm_response for the text approach, offerSigned_cvSummary for the binary approach) contains a valid AI-generated summary.

  4. If the POST activity fails with a 400 Bad Request, check that the file_data value begins with data:application/pdf;base64, and that the base64 string is complete and not truncated.

  5. If the decoded text content looks garbled (for the text approach), confirm the full three-function chain is applied: HexToString(BinaryToHex(Base64Decode(...))). Applying only Base64Decode without the conversion chain returns binary data, not readable text.

Tip

To schedule the operation to run automatically, see Schedule an operation to run automatically.