Sample code for 30+ languages & platforms
Unicode C++

Referencing a Pre-Uploaded Image File by file_id in an AI Request

See more AI Examples

Currently, OpenAI is the only AI provider that supports referencing a pre-uploaded image in a request for text generation.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkAiW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkAiW ai;

    // OpenAI is currently the only AI provider that supports referencing a pre-uploaded image by file_id
    // in a request for text generation.
    ai.put_Provider(L"openai");

    // Use your provider's API key.
    ai.put_ApiKey(L"MY_API_KEY");

    // Choose a model.
    ai.put_Model(L"gpt-5-mini");

    // See the following example showing how to upload a file
    // Upload an Image File to an AI Provider

    // Use the file_id of the pre-uploaded file.
    const wchar_t *file_id = L"file-5CnBeuFasqNcAfti3cx4Fe";
    ai.InputAddImageFileId(file_id,L"application/json");

    ai.InputAddText(L"What is in this image?");

    // Ask the AI for text output.
    success = ai.Ask(L"text");
    if (success == false) {
        wprintf(L"%s\n",ai.lastErrorText());
        return;
    }

    // Get the text response.
    CkStringBuilderW sbResponse;
    ai.GetOutputTextSb(sbResponse);
    wprintf(L"%s\n",sbResponse.getAsString());
    }