googleapis/mcp-toolbox · error

missing credentials for Gemini embedding: For Google AI: Pro

Error message

missing credentials for Gemini embedding: For Google AI: Provide 'apiKey' in YAML or set GOOGLE_API_KEY/GEMINI_API_KEY env vars. For Vertex AI: Provide 'project'/'location' in YAML or via GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars. See documentation for details: https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/

What it means

The Gemini embedding Initialize requires credentials for either the Google AI (Gemini API) backend or Vertex AI. If neither an apiKey/project+location (YAML or well-known env vars) can be resolved, it returns this descriptive error pointing to the docs.

Source

Thrown at internal/embeddingmodels/gemini/gemini.go:97

	if project != "" && location != "" {
		// VertexAI API uses ADC for authentication.
		// ADC requires `Project` and `Location` to be set.
		configs.Backend = genai.BackendVertexAI
		configs.Project = project
		configs.Location = location

		l.InfoContext(ctx, "Using Vertex AI backend for Gemini embedding", "project", project, "location", location)

	} else if apiKey != "" {
		// Using Gemini API, which uses API Key for authentication.
		configs.Backend = genai.BackendGeminiAPI
		configs.APIKey = apiKey

		l.InfoContext(ctx, "Using Google AI (Gemini API) backend for Gemini embedding")

	} else {
		// Missing credentials
		return nil, fmt.Errorf("missing credentials for Gemini embedding: " +
			"For Google AI: Provide 'apiKey' in YAML or set GOOGLE_API_KEY/GEMINI_API_KEY env vars. " +
			"For Vertex AI: Provide 'project'/'location' in YAML or via GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars. " +
			"See documentation for details: https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/")
	}

	// Set user agent
	ua, err := util.UserAgentFromContext(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get user agent from context: %w", err)
	}
	configs.HTTPOptions = genai.HTTPOptions{
		Headers: http.Header{
			"User-Agent": []string{ua},
		},
	}

	// Create new Gemini API client
	client, err := genai.NewClient(ctx, configs)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Set apiKey in the gemini embeddingModel config YAML, or export GOOGLE_API_KEY (or GEMINI_API_KEY)
  2. For Vertex AI, set project and location in YAML or GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars
  3. Verify the env vars are visible to the actual process (echo inside the container/service)
  4. Confirm no typos in env var names and that .env files are loaded
  5. Refer to https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/

Example fix

// before
embeddingModels:
  my-embedding:
    kind: gemini
    model: text-embedding-004
// after
embeddingModels:
  my-embedding:
    kind: gemini
    model: text-embedding-004
    apiKey: ${GOOGLE_API_KEY}
Defensive patterns

Strategy: validation

Validate before calling

func hasGeminiCreds(apiKey, project string) error {
    if apiKey != "" || os.Getenv("GOOGLE_API_KEY") != "" || os.Getenv("GEMINI_API_KEY") != "" {
        return nil
    }
    if project != "" || os.Getenv("GOOGLE_CLOUD_PROJECT") != "" {
        return nil
    }
    return errors.New("gemini embedding: no apiKey or Vertex project/location configured")
}

Try / catch

model, err := cfg.Initialize(ctx)
if err != nil && strings.Contains(err.Error(), "missing credentials for Gemini embedding") {
    cfg.ApiKey = os.Getenv("GOOGLE_API_KEY")
    model, err = cfg.Initialize(ctx)
}

Prevention

When it happens

Trigger: Config with no apiKey and GOOGLE_API_KEY/GEMINI_API_KEY unset, and no project/location in YAML or GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION set; env vars present but not visible to the process (wrong shell, container, or service account).

Common situations: Deploying to Cloud Run/GKE where env vars weren't set; typos in env var names; using Vertex AI mode but forgetting project/location; dotenv file not loaded in the container image.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/91d0064d6f36e6bd. Report an issue: GitHub.