Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure OpenAI Provider is not working as expected #588

Open
I-Amarjeet opened this issue Dec 4, 2024 · 1 comment
Open

Azure OpenAI Provider is not working as expected #588

I-Amarjeet opened this issue Dec 4, 2024 · 1 comment

Comments

@I-Amarjeet
Copy link

Hi, I am trying to connect to Azure OpenAI deployment model but I keep getting the following error.

return {
57 | responseHeaders,
58 | value: new APICallError({
| ^
59 | message: errorToMessage(parsedError),
60 | url,
61 | requestBodyValues, {
cause: undefined,
url: 'https://my-resource-name-goes-here.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-02-15-preview',
requestBodyValues: [Object],
statusCode: 401,
responseHeaders: [Object],
responseBody: '{"error":{"code":"Unauthorized","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}',
isRetryable: false,
data: [Object]
}

Following is the code that I am using to configure Azure OpenAI

import { createAzure } from '@ai-sdk/azure';

//import { azure } from '@ai-sdk/azure';

import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai';

import { customMiddleware } from './custom-middleware';

const azure = createAzure({
  apiKey: process.env.AZURE_API_KEY, // Azure API key
  resourceName: process.env.AZURE_RESOURCE_NAME, // Azure resource name
  apiVersion: process.env.AZURE_API_VERSION, // Azure API version
}); 

export const customModel = (apiIdentifier: string) => {
  return wrapLanguageModel({
    model: azure(apiIdentifier),
    middleware: customMiddleware,
  }); 
};

As per documentation this should work.

I am able to use the API from my FastAPI Python code. So I know that the endpoints, api-key, api-version, resource name parameters are correct and I do have valid subscription.

@I-Amarjeet I-Amarjeet changed the title Azure OpenAI Provider is not fully supported Azure OpenAI Provider is not working as expected Dec 4, 2024
@jeremyphilemon
Copy link
Collaborator

Thanks for reporting! From the error message it looks like the API calls are reported as unauthorized so it may be an issue with the provider not being able to read the correct API keys from the environment.

Can you confirm if you've specified the azure environment variables in env.local?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants