weaviate/weaviate · error

no api key found neither in request header: X-Mistral-Api-Ke

Error message

no api key found neither in request header: X-Mistral-Api-Key nor in environment variable under MISTRAL_APIKEY

What it means

The generative-mistral module resolves the Mistral API key in getApiKey() by checking the request context header X-Mistral-Api-Key, then the module-level key loaded from the MISTRAL_APIKEY environment variable at startup. If both are absent, Generate fails with this error and no inference request is made.

Source

Thrown at modules/generative-mistral/clients/mistral.go:201

	return nil
}

func (v *mistral) getMistralUrl(ctx context.Context, baseURL string) (string, error) {
	passedBaseURL, err := modulecomponents.ValidatedBaseURLFromHeader(ctx, "X-Mistral-Baseurl", baseURL)
	if err != nil {
		return "", err
	}
	return url.JoinPath(passedBaseURL, "/v1/chat/completions")
}

func (v *mistral) getApiKey(ctx context.Context) (string, error) {
	if apiKey := modulecomponents.GetValueFromContext(ctx, "X-Mistral-Api-Key"); apiKey != "" {
		return apiKey, nil
	}
	if v.apiKey != "" {
		return v.apiKey, nil
	}
	return "", errors.New("no api key found " +
		"neither in request header: X-Mistral-Api-Key " +
		"nor in environment variable under MISTRAL_APIKEY")
}

type generateInput struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	Temperature *float64  `json:"temperature,omitempty"`
	TopP        *float64  `json:"top_p,omitempty"`
	MaxTokens   *int      `json:"max_tokens,omitempty"`
}

type generateResponse struct {
	Choices []Choice
	Usage   *usage           `json:"usage,omitempty"`
	Error   *mistralApiError `json:"error,omitempty"`
}

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Set MISTRAL_APIKEY in the server environment and restart Weaviate (e.g. docker-compose environment: MISTRAL_APIKEY=<key>).
  2. Pass the key per-request via the X-Mistral-Api-Key header in your client's request headers options.
  3. Verify the module is enabled (ENABLE_MODULES=generative-mistral) so the env var is read at startup.
  4. Check that the env var value is a valid non-empty Mistral API key.

Example fix

// before: server env
services:
  weaviate:
    environment:
      ENABLE_MODULES: generative-mistral
// after
services:
  weaviate:
    environment:
      ENABLE_MODULES: generative-mistral
      MISTRAL_APIKEY: ${MISTRAL_APIKEY}
Defensive patterns

Strategy: validation

Validate before calling

import os
assert os.environ.get('MISTRAL_APIKEY'), 'Set MISTRAL_APIKEY before starting Weaviate'

Try / catch

try:
    result = collection.generate(...)
except WeaviateError as e:
    if 'no api key found' in str(e) and 'Mistral' in str(e):
        configure_api_key_header('X-Mistral-Api-Key')
    else:
        raise

Prevention

When it happens

Trigger: Calling a near_text/generative (Get{ ... _additional { generate } }) query on a class with generative-mistral configured, when no X-Mistral-Api-Key header is sent with the GraphQL request and the server was started without MISTRAL_APIKEY set (or without ENABLE_MODULES=generative-mistral picking it up).

Common situations: Running Weaviate in Docker/Kubernetes without passing -e MISTRAL_APIKEY; setting the key under a misspelled env var name; clients (e.g. Python/JS v4) not passing the header in the request options; key present but empty string.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/c7d89776771f10f5. Report an issue: GitHub.