Sample code for 30+ languages & platforms
DataFlex

Multimodal Input: Image URL

See more AI Examples

Demonstrates sending a request that includes both text and an image URL for the AI to analyze.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoAi
    Variant vSbResponse
    Handle hoSbResponse
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatAi)) To hoAi
    If (Not(IsComObjectCreated(hoAi))) Begin
        Send CreateComObject of hoAi
    End

    // The provider can be "openai", "google", "claude", "deepseek", "xai", or "perplexity".
    // Support for additional providers will be added in future versions of Chilkat.
    Set ComProvider Of hoAi To "google"

    // Use your provider's API key.
    Set ComApiKey Of hoAi To "MY_API_KEY"

    // Choose a model.
    Set ComModel Of hoAi To "gemini-2.5-flash"

    // Add both text input, and an image URL.
    // If the AI provider does not natively support image URLs, Chilkat will download the image data to memory and send the image data to the AI provider (within the "Ask" method call).
    Get ComInputAddText Of hoAi "Describe what you see in the following image." To iSuccess
    Get ComInputAddImageUrl Of hoAi "https://www.chilkatsoft.com/images/starfish.jpg" "" To iSuccess

    // Ask the AI for text output.
    Get ComAsk Of hoAi "text" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoAi To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the text response.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
    If (Not(IsComObjectCreated(hoSbResponse))) Begin
        Send CreateComObject of hoSbResponse
    End
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComGetOutputTextSb Of hoAi vSbResponse To iSuccess
    Get ComGetAsString Of hoSbResponse To sTemp1
    Showln sTemp1

    // -------------------------------------------------------------
    // The response is in markdown format.
    // Also see Markdown to HTML Conversion Examples.
    // -------------------------------------------------------------

    // Sample output:

    // The image displays a single, vibrant **starfish** set against a plain **white background**.
    // 
    // Here's a more detailed description:
    // 
    // *   **Object:** A single starfish.
    // *   **Shape:** It has the characteristic five-pointed star shape, with each arm tapering slightly to a rounded end. The arms appear somewhat plump and substantial.
    // *   **Color:** The starfish is a beautiful **warm, golden-orange color**, with subtle variations in hue that suggest natural texture and depth. Some areas might lean a little more yellow, while others have a slightly richer, deeper orange tone.
    // *   **Texture:** Its entire surface is visibly **textured**, covered in numerous small, raised bumps or granular patterns. These details are consistent across all the arms and the central body, giving it a rough, almost sandpaper-like appearance, typical of a real starfish.
    // *   **Lighting & Depth:** The lighting on the starfish highlights these textures, creating subtle shadows in the crevices between the bumps and making the object appear distinctly three-dimensional and lifelike. The light seems to come from above, casting gentle shadows that define its form.
    // *   **Background:** The starfish is isolated against a pure white, featureless background, which makes it stand out prominently as the sole subject of the image.
    // 
    // Overall, it's a clear, well-lit photograph of a textured, orange starfish.


End_Procedure