Skip to main content

Azure OpenAI Integration

Route your Azure OpenAI Service traffic through Rivaro for runtime enforcement. Deployment-based URL structure, authentication, and Azure-specific configuration.

SDK Configuration

Python

from openai import AzureOpenAI

client = AzureOpenAI(
api_key="your-azure-api-key",
api_version="2024-02-15-preview",
azure_endpoint="https://your-org.rivaro.ai",
default_headers={
"X-Detection-Key": "detect_live_your_key_here"
}
)

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
apiKey: 'your-azure-api-key',
baseURL: 'https://your-org.rivaro.ai/openai/deployments/your-deployment-name',
defaultHeaders: {
'X-Detection-Key': 'detect_live_your_key_here',
'api-key': 'your-azure-api-key'
},
defaultQuery: {
'api-version': '2024-02-15-preview'
}
});

curl

curl "https://your-org.rivaro.ai/openai/deployments/gpt-4/chat/completions?api-version=2024-02-15-preview" \
-H "Content-Type: application/json" \
-H "api-key: your-azure-api-key" \
-H "X-Detection-Key: detect_live_your_key_here" \
-d '{
"messages": [{"role": "user", "content": "Hello"}]
}'

Supported Endpoints

EndpointMethodDescription
/openai/deployments/{deploymentId}/chat/completionsPOSTChat completions
/openai/deployments/{deploymentId}/completionsPOSTText completions (legacy)
/openai/modelsGETList models

Request and response formats match the Azure OpenAI REST API exactly.

Key Differences from OpenAI

No model field in request body

Azure OpenAI uses the deployment name in the URL path instead of a model field in the request body. The deployment determines which model is used.

# OpenAI: model in body
POST /v1/chat/completions
{"model": "gpt-4", "messages": [...]}

# Azure: model determined by deployment in URL
POST /openai/deployments/my-gpt4-deployment/chat/completions
{"messages": [...]}

api-version query parameter

Include the api-version query parameter in your requests. Rivaro passes it through to Azure unchanged.

/openai/deployments/gpt-4/chat/completions?api-version=2024-02-15-preview

Authentication header

Azure uses api-key instead of Authorization: Bearer:

HeaderDescription
api-keyYour Azure OpenAI API key (primary)
x-api-keyAccepted as fallback (converted to api-key)

Required Headers

HeaderRequiredDescription
X-Detection-KeyYesYour Rivaro detection key
api-keyYesYour Azure OpenAI API key
Content-TypeYesapplication/json

Streaming

Streaming works the same as with OpenAI. Set "stream": true in the request body. Content chunks are forwarded in real time; enforcement runs on the accumulated response after the stream completes.

Blocked Requests

Blocked responses match the OpenAI format:

{
"choices": [{
"message": {
"role": "assistant",
"content": "Content blocked due to policy violations"
},
"finish_reason": "content_filter"
}]
}

AppContext Configuration

When creating an AppContext for Azure OpenAI, the configuration map supports:

KeyDescription
azureResourceNameYour Azure OpenAI resource name
azureDeploymentNameDefault deployment name

Next steps