Adding Azure OpenAi and Other LLMs

Hello , So i was just trying to add azure openai Any model for now just testing : and now its making me go crazy with errors : with some error like this and now i want someone to help me intigrate Azure Ai in it: Error getting Azure OpenAI models: Error: Error fetching models: Resource Not Found
at Object.getAzureOpenAIModels [as getDynamicModels] (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:339:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Promise.all (index 3)
at async Module.initializeModelList (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:418:9)
at async handleRequest (C:/Projects/ai/bolt.new-any-llm/app/entry.server.tsx:30:3)
at async handleDocumentRequest (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:349:12)
at async requestHandler (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:160:18)
at async C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+dev@2.10.0_@remix-run+react@2.10.2_react-dom@18.3.1_react@18.3.1__react@18.3.1_typ_qwyxqdhnwp3srgtibfrlais3ge\node_modules@remix-run\dev\dist\vite\cloudflare-proxy-plugin.js:70:25
Error getting Azure OpenAI models: Error: Error fetching models: Resource Not Found
at Object.getAzureOpenAIModels [as getDynamicModels] (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:339:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Promise.all (index 3)
at async Module.initializeModelList (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:418:9)
at async handleRequest (C:/Projects/ai/bolt.new-any-llm/app/entry.server.tsx:30:3)
at async handleDocumentRequest (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:349:12)
at async requestHandler (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:160:18)
at async C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+dev@2.10.0_@remix-run+react@2.10.2_react-dom@18.3.1_react@18.3.1__react@18.3.1_typ_qwyxqdhnwp3srgtibfrlais3ge\node_modules@remix-run\dev\dist\vite\cloudflare-proxy-plugin.js:70:25
Error getting Azure OpenAI models: Error: Error fetching models: Resource Not Found
at Object.getAzureOpenAIModels [as getDynamicModels] (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:339:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Promise.all (index 3)
at async Module.initializeModelList (C:/Projects/ai/bolt.new-any-llm/app/utils/constants.ts:418:9)
at async handleRequest (C:/Projects/ai/bolt.new-any-llm/app/entry.server.tsx:30:3)
at async handleDocumentRequest (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:349:12)
at async requestHandler (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:160:18)
at async C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+dev@2.10.0_@remix-run+react@2.10.2_react-dom@18.3.1_react@18.3.1__react@18.3.1_typ_qwyxqdhnwp3srgtibfrlais3ge\node_modules@remix-run\dev\dist\vite\cloudflare-proxy-plugin.js:70:25
TypeError: Failed to parse URL from /api/chat
at node:internal/deps/undici/undici:13392:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async postToApi (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@ai-sdk+provider-utils@1.0.20_zod@3.23.8\node_modules@ai-sdk\provider-utils\dist\index.js:388:22) {
[cause]: TypeError: Invalid URL
at new URL (node:internal/url:816:29)
at new Request (node:internal/deps/undici/undici:9474:25)
at fetch (node:internal/deps/undici/undici:10203:25)
at fetch (node:internal/deps/undici/undici:13390:10)
at fetch (node:internal/bootstrap/web/exposed-window-or-worker:72:12)
at postToApi (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@ai-sdk+provider-utils@1.0.20_zod@3.23.8\node_modules@ai-sdk\provider-utils\dist\index.js:388:28)
at postJsonToApi (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@ai-sdk+provider-utils@1.0.20_zod@3.23.8\node_modules@ai-sdk\provider-utils\dist\index.js:363:7)
at OllamaChatLanguageModel.doStream (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm\ollama-ai-provider@0.15.2_zod@3.23.8\node_modules\ollama-ai-provider\dist\index.js:485:97)
at fn (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:3938:35)
at file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:256:28
at Object.startActiveSpan (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:185:14)
at recordSpan (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:254:17)
at file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:3904:17
at retryWithExponentialBackoff (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:86:18)
at file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:75:25
at startStep (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:3903:19)
at fn (file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:3977:17)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///C:/Projects/ai/bolt.new-any-llm/node_modules/.pnpm/ai@3.4.9_react@18.3.1_sswr@2.1.0_svelte@4.2.18__svelte@4.2.18_vue@3.4.30_typescript@5.5.2__zod@3.23.8/node_modules/ai/dist/index.mjs:256:22
at async chatAction (C:/Projects/ai/bolt.new-any-llm/app/routes/api.chat.ts:64:20)
at async Object.callRouteAction (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\data.js:37:16)
at async C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:4612:21
at async callLoaderOrAction (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:4677:16)
at async Promise.all (index 1)
at async callDataStrategyImpl (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:4552:17)
at async callDataStrategy (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:4041:19)
at async submit (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:3900:21)
at async queryImpl (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:3858:22)
at async Object.queryRoute (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+router@1.17.0\node_modules@remix-run\router\dist\router.cjs.js:3827:18)
at async handleResourceRequest (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:413:20)
at async requestHandler (C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+server-runtime@2.10.0_typescript@5.5.2\node_modules@remix-run\server-runtime\dist\server.js:156:18)
at async C:\Projects\ai\bolt.new-any-llm\node_modules.pnpm@remix-run+dev@2.10.0
@remix-run+react@2.10.2_react-dom@18.3.1_react@18.3.1__react@18.3.1_typ_qwyxqdhnwp3srgtibfrlais3ge\node_modules@remix-run\dev\dist\vite\cloudflare-proxy-plugin.js:70:25 {
code: ‘ERR_INVALID_URL’,
input: ‘/api/chat’
} or help me solve this error

Could you please share what you have done so far for your setup with Azure OpenAI?

Sure As So I Started with modify app/utils/contsant.ts file Added Proiderlist:
// Azure api
{
name: ‘AzureOpenAI’,
staticModels: [
{ name: ‘gpt-4’, label: ‘GPT-4’, provider: ‘AzureOpenAI’, maxTokenAllowed: 8000 },
{ name: ‘gpt-3.5-turbo’, label: ‘GPT-3.5 Turbo’, provider: ‘AzureOpenAI’, maxTokenAllowed: 8000 },
],
getDynamicModels: getAzureOpenAIModels,
getApiKeyLink: ‘Microsoft Azure’,
labelForGetApiKey: ‘Get Azure API Key’,
icon: ‘i-ph:cloud-arrow-down’,
},

// end of Azure api
This is Just 2 bcs i am testing first if it workes later add more.
Than Added Function To call Api but that is somehow creating issue i guess:
// Azure function start
async function getAzureOpenAIModels(): Promise<ModelInfo> {
try {
const baseUrl = process.env.AZURE_API_ENDPOINT || ‘’; // Get base URL from env
const apiKey = process.env.AZURE_API_KEY || ‘’; // Get API key from env

// Check if base URL and API key are missing
if (!baseUrl || !apiKey) {
  throw new Error('Missing Azure API endpoint or API key');
}

// The URL for fetching models (adjusted based on your endpoint)
const url = `${baseUrl}/openai/deployments/gpt-4/chat/completions?api-version=2024-08-01-preview`;

// Fetch the models from the Azure endpoint
const response = await fetch(url, {
  method: 'GET', // GET request to fetch models
  headers: {
    'Content-Type': 'application/json',
    'api-key': apiKey, // API Key for authorization
  },
});

// Check if the response is okay
if (!response.ok) {
  throw new Error(`Error fetching models: ${response.statusText}`);
}

const data = await response.json();

// Check if the response has the necessary data structure
if (!data || !Array.isArray(data.value)) {
  throw new Error('Invalid response format');
}

// Process the data and map it to your ModelInfo structure
return data.value.map((model: any) => ({
  name: model.id, // Model ID
  label: model.id, // You can add more meaningful labels here
  provider: 'AzureOpenAI', // Provider name
  maxTokenAllowed: 8000, // You can adjust the token limit if necessary
}));

} catch (e) {
console.error(‘Error getting Azure OpenAI models:’, e);
return ; // Return an empty array on error
}
}

// Azure function ends
Just for your Refrence :Azure Api looks like this : https://ai-demoapi1764ai556789877.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2024-08-01-preview
And have Api Key for this. Let me Know if you want to know More details for this Query

I appreciate you sharing the details!

To be honest I haven’t used the Azure OpenAI API myself, but I’m hoping someone else here has and can help based on the details you gave!

Did you get it to work? I need to add an Azure model

nope , did you made it?

@aliasfox you had this integrated in a PR and wanted to take a look what needs to be done to get it in the main/stable, or am I wrong?

I haven’t touched any of this since holiday and there’s been a bunch of changes, including structural… So I’d have to take a look. And there’s actually a few PR’s I would like to submit.

As a note, I saw a post that someone got this to work without modifying code by using the OpenAI-Like option, but I’m not clear the options.

Been busy, but I’ll take a look later (after work).

1 Like