Forum Discussion
Cannot connect Azure OpenAI Embeddings model to SQL Server 2025
On SQL Server 2025, I am trying to vectorize a table.
To set up the ability for SQL Server 2025 to communicate with Azure OpenAI embeddings model, I first created a master key for encryption.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Secret';
GO
Then I set up a database scoped credential.
CREATE DATABASE SCOPED CREDENTIAL [MyAzureOpenAICredential]
WITH IDENTITY = 'HTTPEndpointHeaders',
SECRET = '{"api-key":"secret"}';
Then I created an external model.
CREATE EXTERNAL MODEL AzureOpenAIEmbeddingsModelWITH (LOCATION = 'https://{secret}-eastus2.cognitiveservices.azure.com/openai/deployments/text-embedding-3-small/embeddings?api-version=2023-05-15',API_FORMAT = 'Azure OpenAI',MODEL_TYPE = EMBEDDINGS,MODEL = 'text-embedding-3-small',CREDENTIAL = [MyAzureOpenAICredential]);
DECLARE @text NVARCHAR(MAX) = N'SQL Server 2025 enables AI-powered applications';
DECLARE @embedding VECTOR(1536) = AI_GENERATE_EMBEDDINGS(@text USE MODEL AzureOpenAIEmbeddingsModel);
The database scoped credential 'MyAzureOpenAICredential' cannot be used to invoke an external rest endpoint.
1 Reply
The credential name is likely the issue. For an external REST endpoint, SQL Server matches the database-scoped credential by URL. Name it with the endpoint’s scheme and host, including the trailing slash, rather than an arbitrary label. Use the exact Azure OpenAI resource origin, keep IDENTITY = 'HTTPEndpointHeaders', store the api-key JSON in SECRET, and reference that credential from CREATE EXTERNAL MODEL.
Set LOCATION to the deployed embeddings endpoint with a supported API version. The MODEL value must match the deployed embedding model, and the vector dimensions must match that deployment’s output dimensions.
If it still fails, test DNS and HTTPS reachability from the SQL Server host, then inspect Azure OpenAI firewall or private-endpoint rules. Recreate only the credential and external model after correcting the URL. Do not include the real key in screenshots or diagnostics; rotate it if it has appeared anywhere public.