Prompt Chain

Integrate Azure OpenAI for text and vision generation

A promptfoo example for evaluating Azure OpenAI text generation and vision models, including three image input methods.

Works with azureopenai

89
Spark score
out of 100
Updated 21 days ago
Version 0.121.18
Models

Add to Favorites

Why it matters

Enable developers to quickly set up and test Azure OpenAI capabilities including text generation and vision models through a standardized evaluation framework with promptfoo.

Outcomes

What it gets done

01

Configure Azure OpenAI endpoints and API authentication

02

Run text generation evaluations with GPT models

03

Test vision models with URL, local file, and base64 images

04

Troubleshoot deployment and API connection issues

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-openai | bash

Steps

Steps in the chain

01
Initialize Azure OpenAI example
02
Set environment variables
03
Update apiHost configuration
04
Update deployment names
05
Run basic text generation evaluation
06
Run vision models evaluation

Overview

Openai

A promptfoo example for evaluating Azure OpenAI text and vision models, with configs covering three image-input methods for vision tasks. Use it to test Azure OpenAI text or vision deployments with promptfoo. Requires an Azure OpenAI account, deployed models, and endpoint configuration.

What it does

This promptfoo example demonstrates using Azure OpenAI with promptfoo for both text generation and vision capabilities. It covers text models like gpt-5.1 and gpt-4o, and vision-capable models such as gpt-4o, and includes separate configs for basic text evaluation and vision evaluation.

When to use - and when NOT to

Use this example when you want to run promptfoo evaluations against your own Azure OpenAI deployments, whether for plain text generation or for vision tasks that need image input. It requires an Azure account with Azure OpenAI Service access, deployed models matching the ones referenced in the config, and your Azure OpenAI endpoint URL - the config files need their apiHost and deployment names updated to match your actual Azure setup before running.

Inputs and outputs

Run basic text generation with the default config, or vision evaluation with a dedicated config file:

npx promptfoo@latest eval
### or
npx promptfoo@latest eval -c promptfooconfig.yaml

### Vision Models
npx promptfoo@latest eval -c promptfooconfig.vision.yaml

The vision example demonstrates three distinct ways to supply an image to a vision model: a direct URL to a web-hosted image, a local file referenced via a file:// path (automatically converted to base64), and a pre-encoded base64 data URI.

Integrations

Set AZURE_API_KEY (or the alternative AZURE_OPENAI_API_KEY) in your environment or a .env file. If you get a 401 error, check that the key is set correctly, that the endpoint URL omits the https:// prefix, and that the deployment actually supports the capability you're requesting (e.g. vision). Full details are in promptfoo's Azure OpenAI provider docs and Microsoft's Azure OpenAI and vision documentation.

Who it's for

Teams evaluating Azure OpenAI deployments - text or vision - with promptfoo, who want working example configs for both capability types plus all three image-input methods already set up.

Source README

azure/openai (Azure OpenAI)

This example demonstrates how to use Azure OpenAI with promptfoo, including text generation and vision capabilities.

You can run this example with:

npx promptfoo@latest init --example azure/openai
cd azure/openai

Environment Variables

This example requires the following environment variables:

  • AZURE_API_KEY - Your Azure OpenAI API key
  • AZURE_OPENAI_API_KEY - Alternative environment variable for your Azure OpenAI API key

You can set these in a .env file or directly in your environment.

Prerequisites

  1. An Azure account with access to Azure OpenAI Service
  2. Deployments for one or more Azure OpenAI models:
    • Text models: gpt-5.1, gpt-4o
    • Vision models: gpt-4o (or other vision-capable models)
  3. Your Azure OpenAI endpoint URL

Setup Instructions

  1. Update the apiHost in the configuration files to your Azure OpenAI endpoint
  2. Set AZURE_API_KEY in your environment
  3. Update the deployment names to match your actual deployments

Available Examples

Basic Text Generation

npx promptfoo@latest eval
### or
npx promptfoo@latest eval -c promptfooconfig.yaml

Vision Models

npx promptfoo@latest eval -c promptfooconfig.vision.yaml

Demonstrates three ways to provide images to vision models:

  • URL: Direct link to an image on the web
  • Local file: Using file:// paths (automatically converted to base64)
  • Base64: Pre-encoded image data URI

Troubleshooting

If you get a 401 error:

  • Ensure your AZURE_API_KEY is set correctly
  • Verify your endpoint URL is correct (no https://)
  • Check that your deployment supports the requested capabilities

Additional Resources

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.