Using Azure OpenAI with Flowstack

Azure OpenAI can be integrated with Flowstack using REST API, Python, and Node.js. Below are the implementation details for each method.

1. Using REST API

To make a request to Azure OpenAI using the REST API, use the following Curl command. Replace YOUR_AZURE_KEY, YOUR_AZURE_MODEL, and YOUR_AZURE_DOMAIN with your Azure key, model name, and domain, respectively.

curl --request POST \
--url "https://openai.flowstack.ai/v1/chat/completions" \
--header "Authorization: Bearer YOUR_AZURE_KEY" \
--header "Content-Type: application/json" \
--header "Flowstack-Auth: Bearer YOUR_FLOWSTACK_KEY" \
--header "Azure-Domain: YOUR_AZURE_DOMAIN.openai.azure.com" \
--data '{
    "model": "YOUR_AZURE_MODEL",
    "messages": [
        {
            "role": "user",
            "content": "Hi!"
        }
    ]
}'

2. Using Python

For integrating Azure OpenAI with Python, use the following script. Be sure to replace YOUR_AZURE_KEY, YOUR_AZURE_DOMAIN, and YOUR_FLOWSTACK_KEY with your Azure API key, domain, and Flowstack key.

from openai import AzureOpenAI

client = AzureOpenAI(
    api_version="2023-05-15",
    azure_endpoint="https://openai.flowstack.ai",
    api_key="YOUR_AZURE_KEY",
    default_headers={
        "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY",
        "Azure-Domain": "YOUR_AZURE_DOMAIN.openai.azure.com",
    }
)

completion = client.chat.completions.create(
    model="YOUR_AZURE_MODEL",
    messages=[
        {
            "role": "user",
            "content": "Hi!",
        },
    ],
)

3. Using Node.js

For Node.js integration with Azure OpenAI, follow the example below. Replace YOUR_AZURE_API_KEY, YOUR_AZURE_DOMAIN, YOUR_AZURE_MODEL, and YOUR_FLOWSTACK_KEY with the respective credentials.

import OpenAI from 'openai';

const openai = new OpenAI({
    apiKey: YOUR_AZURE_API_KEY,
    baseURL: "https://YOUR_AZURE_DOMAIN.openai.azure.com/openai/deployments/YOUR_AZURE_MODEL",
    defaultQuery: { 'api-version': '2023-05-15' },
    defaultHeaders: { 
        "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY",
        "Azure-Domain": "YOUR_AZURE_DOMAIN.openai.azure.com"
    },
});

const response = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    messages: [
        {"role": "user", "content": "Hello!"}
    ]
});

console.log(response.data);

Streaming Support

Please note that Flowstack’s Azure AI integration supports streaming responses.