danny-avila/LibreChat · error · Error

Missing AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_IN

Error message

Missing AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_INDEX_NAME, or AZURE_AI_SEARCH_API_KEY environment variable.

What it means

Thrown by the AzureAISearch tool constructor when, after resolving each value via _initializeField (field arg → process.env → default), at least one of serviceEndpoint, indexName, or apiKey is still empty. The override flag exists specifically to let the app bootstrap and register the tool manifest without these vars. When override is false the constructor hard-fails, because it immediately proceeds to instantiate an @azure/search-documents SearchClient with those values.

Source

Thrown at api/app/clients/tools/structured/AzureAISearch.js:73

    );
    this.queryType = this._initializeField(
      fields.AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE,
      'AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE',
      AzureAISearch.DEFAULT_QUERY_TYPE,
    );
    this.top = this._initializeField(
      fields.AZURE_AI_SEARCH_SEARCH_OPTION_TOP,
      'AZURE_AI_SEARCH_SEARCH_OPTION_TOP',
      AzureAISearch.DEFAULT_TOP,
    );
    this.select = this._initializeField(
      fields.AZURE_AI_SEARCH_SEARCH_OPTION_SELECT,
      'AZURE_AI_SEARCH_SEARCH_OPTION_SELECT',
    );

    // Check for required fields
    if (!this.override && (!this.serviceEndpoint || !this.indexName || !this.apiKey)) {
      throw new Error(
        'Missing AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_INDEX_NAME, or AZURE_AI_SEARCH_API_KEY environment variable.',
      );
    }

    if (this.override) {
      return;
    }

    // Create SearchClient
    this.client = new SearchClient(
      this.serviceEndpoint,
      this.indexName,
      new AzureKeyCredential(this.apiKey),
      { apiVersion: this.apiVersion },
    );
  }

  // Improved error handling and logging

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Set the three env vars in your environment/.env: AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_INDEX_NAME, AZURE_AI_SEARCH_API_KEY (verify with `printenv | grep AZURE_AI_SEARCH`).
  2. If you are only initializing the tool registry/manifest (no actual search call), pass `override: true` in the fields object so the constructor skips the check and the SearchClient creation.
  3. If you mean to use the tool, pass the values explicitly via the constructor fields object (keys: AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_INDEX_NAME, AZURE_AI_SEARCH_API_KEY) so it does not depend on env.
  4. Confirm there is no trailing typo in the env var names — _initializeField reads process.env[envVar] verbatim and is case-sensitive.

Example fix

// before
const tool = new AzureAISearch({}); // throws if env vars unset

// after (app bootstrap / manifest load)
const tool = new AzureAISearch({ override: true });

// after (real usage)
const tool = new AzureAISearch({
  AZURE_AI_SEARCH_SERVICE_ENDPOINT: endpoint,
  AZURE_AI_SEARCH_INDEX_NAME: index,
  AZURE_AI_SEARCH_API_KEY: key,
});
Defensive patterns

Strategy: validation

Validate before calling

function assertAzureAISearchConfig(fields = {}) {
  const env = process.env;
  const endpoint = fields.AZURE_AI_SEARCH_SERVICE_ENDPOINT || env.AZURE_AI_SEARCH_SERVICE_ENDPOINT;
  const index = fields.AZURE_AI_SEARCH_INDEX_NAME || env.AZURE_AI_SEARCH_INDEX_NAME;
  const key = fields.AZURE_AI_SEARCH_API_KEY || env.AZURE_AI_SEARCH_API_KEY;
  const missing = [!endpoint && 'endpoint', !index && 'index', !key && 'apiKey'].filter(Boolean);
  if (missing.length && !fields.override) {
    throw new Error('AzureAISearch config missing: ' + missing.join(', '));
  }
}
// call before: assertAzureAISearchConfig(fields); new AzureAISearch(fields);

Type guard

function hasAzureAISearchConfig(fields) {
  const env = process.env;
  return Boolean(
    (fields.AZURE_AI_SEARCH_SERVICE_ENDPOINT || env.AZURE_AI_SEARCH_SERVICE_ENDPOINT) &&
      (fields.AZURE_AI_SEARCH_INDEX_NAME || env.AZURE_AI_SEARCH_INDEX_NAME) &&
      (fields.AZURE_AI_SEARCH_API_KEY || env.AZURE_AI_SEARCH_API_KEY),
  );
}

Prevention

When it happens

Trigger: Constructing `new AzureAISearch({...})` (or any code path that loads structured tools, e.g. tool manifest initialization at startup) where AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_INDEX_NAME, or AZURE_AI_SEARCH_API_KEY is unset in both the fields argument and process.env, and `fields.override` is not true.

Common situations: Fresh deployment or local dev where the .env file was copied from .env.example but the Azure AI Search keys were never filled in; CI runs missing the secret env vars; a docker container started without the env passthrough; refactoring that renamed the env vars; running tests that instantiate the real tool instead of stubbing it.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/94c7863bf24d6a9f. Report an issue: GitHub.