AI SQL Tuner

Bring Your Own AI Endpoint & Model

This guide explains how to configure AI SQL Tuner to use your own Microsoft Foundry (Azure AI Foundry) setup, including your Azure OpenAI-compatible endpoint and deployment/model.

1) Prerequisites

  • A Microsoft Foundry resource (Azure AI Foundry) in your Azure subscription
  • A Foundry project and a deployed model (deployment name)
  • Your Azure OpenAI-compatible:
    • Endpoint (URL)
    • API key (or a key/secret associated with your project’s model endpoint)

1.1) Create a Microsoft Foundry resource (new Foundry portal)

Microsoft Foundry (formerly Azure AI Foundry) is the portal experience you use to create Foundry resources/projects and work with models and agents:

  1. Open Microsoft Foundry: https://ai.azure.com/
  2. Ensure you’re using the new Foundry portal (there’s a banner toggle in the portal to switch between (new) and (classic)).
  3. Create a Foundry resource and a Foundry project (or select an existing project).
  4. In your project, locate the model endpoint details you’ll use with AI SQL Tuner:
    • Endpoint URL
    • API key

Notes:

  • AI SQL Tuner expects the endpoint to end with /.
  • If you don’t see the resource/project you expect in the new portal, use View all resources to open the classic experience.

1.1.1) Alternative: Provision an Azure OpenAI resource (Azure Portal)

  1. In the Azure Portal, search for Azure OpenAI and choose Create.
  2. Select:
    • Subscription / Resource group
    • Region (must be supported for Azure OpenAI in your tenant)
    • Name (this becomes part of the endpoint host)
  3. Create the resource.
  4. After creation, open the Azure OpenAI resource:
    • Copy the Endpoint (looks like https://<resource>.cognitiveservices.azure.com/)
    • Go to Keys and Endpoint (or similar) and copy Key 1 or Key 2

Notes:

  • The endpoint must be the resource endpoint (not a Portal URL).
  • AI SQL Tuner expects the endpoint to end with /.

1.2) Deploy primary and secondary models (create deployments)

AI SQL Tuner uses a deployment name (not the raw model ID) when calling Azure OpenAI.

  1. Open Microsoft Foundry: https://ai.azure.com/
  2. Select your Foundry project.
  3. Go to your project’s models/deployments area.
  4. Select Create deployment.
  5. Choose the model you want to use (depends on what’s available in your region/tenant).
  6. Give it a Deployment name (example: gpt-5.2, o1-preview, model-router).
  7. Create/save the deployment.
  8. Repeat for the secondary model, which will be used if the primary fails, for example due to be too busy.

You will use this deployment name in AISQLTUNER_DEPLOYMENT.

2) Set environment variables

AI SQL Tuner reads configuration from environment variables first.

Required

Set these two variables:

  • AZURE_OPENAI_ENDPOINT – your Azure OpenAI endpoint URL
  • AZURE_OPENAI_KEY – your Azure OpenAI API key

Optional

  • AISQLTUNER_DEPLOYMENT – overrides the default deployment/model name, which is gpt-5.2 currently
  • AISQLTUNER_SECONDARY_DEPLOYMENT – optional secondary deployment/model name (used when AI SQL Tuner needs a fallback/alternate deployment), currently set to model-router.

3) Windows PowerShell example

# Required
$env:AZURE_OPENAI_ENDPOINT = "https://<your-resource-name>.cognitiveservices.azure.com/"
$env:AZURE_OPENAI_KEY = "<your-azure-openai-key>"

# Optional (deployment name as created in Azure OpenAI)
$env:AISQLTUNER_DEPLOYMENT = "<your-deployment-name>"
$env:AISQLTUNER_SECONDARY_DEPLOYMENT = "<your-secondary-deployment-name>"

# Run
aisqltuner -S <server> -goal ServerHealth -E -o report.html

4) Windows CMD example

REM Required
set AZURE_OPENAI_ENDPOINT=https://<your-resource-name>.cognitiveservices.azure.com/
set AZURE_OPENAI_KEY=<your-azure-openai-key>

REM Optional
set AISQLTUNER_DEPLOYMENT=<your-deployment-name>
set AISQLTUNER_SECONDARY_DEPLOYMENT=<your-secondary-deployment-name>

REM Run
aisqltuner -S <server> -goal ServerHealth -E -o report.html

5) Common configuration problems

“Azure OpenAI endpoint or API key is not configured or is empty”

  • Ensure AZURE_OPENAI_ENDPOINT is set and ends with /
  • Ensure AZURE_OPENAI_KEY is set

Endpoint looks correct but streaming fails

  • Verify the endpoint is the Azure OpenAI resource endpoint (not a portal URL)
  • Ensure the deployment exists under that resource
  • Try a different deployment name via AISQLTUNER_DEPLOYMENT

“Using model/deployment: …” is not what you expected

  • Set AISQLTUNER_DEPLOYMENT explicitly
  • Confirm the deployment name in Azure OpenAI matches exactly (case-sensitive in Azure)

6) Quick checklist

  • [ ] AZURE_OPENAI_ENDPOINT set to https://...cognitiveservices.azure.com/
  • [ ] AZURE_OPENAI_KEY set
  • [ ] AISQLTUNER_DEPLOYMENT set (optional)
  • [ ] Deployment name exists in Azure OpenAI
  • [ ] You can run: aisqltuner -S <server> -goal ServerHealth -E -o report.html

7) Example: Use a different model

If you have a deployment named o1-preview:

$env:AISQLTUNER_DEPLOYMENT = "o1-preview"
aisqltuner -S <server> -goal IndexTuning -E -o index.html

If you have a model-router deployment:

$env:AISQLTUNER_DEPLOYMENT = "model-router"
aisqltuner -S <server> -goal ServerHealth -E -o health.html

If you need support, include:

  • The deployment name you used
  • The exact error message
  • Whether you are using -E (Windows auth), -aad, or SQL auth (-u/-p)

AI SQL Tuner

Thank You, we'll be in touch soon.

© 2025 AI SQL Tuner LLC — AI-Powered SQL Server Optimization. All rights reserved.