Agents SDK (typescript) and Azure OpenAi

I’m trying to switch from my OpenAI account to my Azure account.

According to multiple posts of this forum, python users are able to successfully use the equivalent of the follow code:

import { AzureOpenAI } from ‘openai’;
import {
Agent,
OpenAIResponsesModel,
run,
} from ‘@openai/agents’;

const azureClient = new AzureOpenAI({
baseURL: process.env.AZURE_OPENAI_ENDPOINT,
apiVersion: process.env.AZURE_OPENAI_API_KEY,
apiKey: process.env.AZURE_OPENAI_API_KEY,
});

const agent = new Agent({
model: new OpenAIResponsesModel(azureClient, ‘gpt-4o’),
name: ‘azure-openai’,
instructions: ‘You are a helpful assistant.’,
});

run(agent, ‘What is the weather in Tokyo?’);

Unfortunately, i’m getting an error message:

Argument of type 'AzureOpenAI' is not assignable to parameter of type 'OpenAI'.
  Type 'AzureOpenAI' is missing the following properties from type 'OpenAI': #private, logger, logLevel, fetchOptions, and 2 more.

I’m unsure of where to go from here

1 Like

Here’s a place to go - the Azure documentation of the node.js library Github:

Microsoft’s guide talks a bit more about usage of the companion Azure library, including authentication whether you use a client token (api key) or Azure AD or Entra ID.

Microsoft is the source of support.

I’m getting authorized fine when using the azure API_KEY approach with the openai repo. The code below runs, works and returns: ‘Hello there! :blush: How can I assist you today’.

The problem seems to be that the @openai/agents repo does not accept the AzureOpenAI client as a custom client.

import dotenv from 'dotenv';
import { AzureOpenAI } from 'openai';

const azureClient = new AzureOpenAI({
  apiKey: process.env.AZURE_OPENAI_API_KEY,
  endpoint: process.env.AZURE_OPENAI_ENDPOINT,
  apiVersion: process.env.AZURE_OPENAI_API_VERSION,
});

const response = await azureClient.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Say hello!' }],
  max_tokens: 10,
});

console.log('Response:', response.choices[0]?.message?.content);

I solved the issue by clearing node_modules and re-downloading the newest versions of both ‘openai’ and ‘@openai/agents’

1 Like