Forum Discussion

HassaanFaruq's avatar
HassaanFaruq
Copper Contributor
Jan 29, 2026

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 AzureOpenAIEmbeddingsModel
WITH (
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]
);
However, when I run this simple script:
 
DECLARE @text NVARCHAR(MAX) = N'SQL Server 2025 enables AI-powered applications';
DECLARE @embedding VECTOR(1536) = AI_GENERATE_EMBEDDINGS(@text USE MODEL AzureOpenAIEmbeddingsModel);
I get this error.
The database scoped credential 'MyAzureOpenAICredential' cannot be used to invoke an external rest endpoint.
I have read through https://learn.microsoft.com/en-us/training/modules/build-ai-solutions-sql-server/4-integrate-ai-models pertaining to this task. As well as SQL Server 2025 docs for creating a model. I have also read SQL Server 2025 docs for creating https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-scoped-credential-transact-sql?view=sql-server-ver17. I have not found any answers.

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.