Azure OpenAI

Azure OpenAI is a great alternative to accessing the best models including GPT-4 and more in your private environments. Portkey provides complete support for Azure OpenAI.

Portkey provides a robust and secure gateway to facilitate the integration of various Large Language Models (LLMs) into your applications, including Azure OpenAI.

With Portkey, you can take advantage of features like fast AI gateway access, observability, prompt management, and more, all while ensuring the secure management of your LLM API keys through a virtual key system.

Portkey SDK Integration with Azure OpenAI

Portkey provides a consistent API to interact with models from various providers. To integrate Azure OpenAI with Portkey:

First, add your Azure details to Portkey's Virtual Keys

Here's a step-by-step guide:

  1. Request access to Azure OpenAI here.

  2. Create a resource in the Azure portal here. (This will be your Resource Name)

  3. Deploy a model in Azure OpenAI Studio here. (This will be your Deployment Name)

  4. Now, on Azure OpenAI studio, go to any playground (chat or completions), click on a UI element called "View code". Note down the API version & API key from here. (This will be your Azure API Version & Azure API Key)

When you input these details, the foundation model will be auto populated. More details in this guide.

Now, let's make a request using this virtual key!

1. Install the Portkey SDK

Add the Portkey SDK to your application to interact with Azure OpenAI's API through Portkey's gateway.

npm install --save portkey-ai

2. Initialize Portkey with the Virtual Key

Set up Portkey with your virtual key as part of the initialization configuration. You can create a virtual key for Azure in the UI.

import Portkey from 'portkey-ai'
 
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
    virtualKey: "VIRTUAL_KEY" // Your Azure Virtual Key
})

3. Invoke Chat Completions with Azure OpenAI

Use the Portkey instance to send requests to your Azure deployments. You can also override the virtual key directly in the API call if needed.

const chatCompletion = await portkey.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt4', // This would be your deployment or model name
});

console.log(chatCompletion.choices);

Managing Azure OpenAI Prompts

You can manage all prompts to Azure OpenAI in the Prompt Library. All the current models of OpenAI are supported and you can easily start testing different prompts.

Once you're ready with your prompt, you can use the portkey.prompts.completions.create interface to use the prompt in your application.

Image Generation

Portkey supports multiple modalities for Azure OpenAI and you can make image generation requests through Portkey's AI Gateway the same way as making completion calls.

import Portkey from 'portkey-ai'
 
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",
    virtualKey: "DALL-E_VIRTUAL_KEY" // Referencing a Dall-E Azure deployment with Virtual Key
})

const image = await portkey.images.generate({
  prompt:"Lucy in the sky with diamonds",
  size:"1024x1024"
})

Portkey's fast AI gateway captures the information about the request on your Portkey Dashboard. On your logs screen, you'd be able to see this request with the request and response.

More information on image generation is available in the API Reference.

Next Steps

The complete list of features supported in the SDK are available on the link below.

pagePortkey SDK Client

You'll find more information in the relevant sections:

Last updated