{"record":{"id":"91d0064d6f36e6bd","repo":"googleapis/mcp-toolbox","slug":"missing-credentials-for-gemini-embedding-for-goog","errorCode":null,"errorMessage":"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/","messagePattern":"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/","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/embeddingmodels/gemini/gemini.go","lineNumber":97,"sourceCode":"\tif project != \"\" && location != \"\" {\n\t\t// VertexAI API uses ADC for authentication.\n\t\t// ADC requires `Project` and `Location` to be set.\n\t\tconfigs.Backend = genai.BackendVertexAI\n\t\tconfigs.Project = project\n\t\tconfigs.Location = location\n\n\t\tl.InfoContext(ctx, \"Using Vertex AI backend for Gemini embedding\", \"project\", project, \"location\", location)\n\n\t} else if apiKey != \"\" {\n\t\t// Using Gemini API, which uses API Key for authentication.\n\t\tconfigs.Backend = genai.BackendGeminiAPI\n\t\tconfigs.APIKey = apiKey\n\n\t\tl.InfoContext(ctx, \"Using Google AI (Gemini API) backend for Gemini embedding\")\n\n\t} else {\n\t\t// Missing credentials\n\t\treturn nil, fmt.Errorf(\"missing credentials for Gemini embedding: \" +\n\t\t\t\"For Google AI: Provide 'apiKey' in YAML or set GOOGLE_API_KEY/GEMINI_API_KEY env vars. \" +\n\t\t\t\"For Vertex AI: Provide 'project'/'location' in YAML or via GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars. \" +\n\t\t\t\"See documentation for details: https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/\")\n\t}\n\n\t// Set user agent\n\tua, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get user agent from context: %w\", err)\n\t}\n\tconfigs.HTTPOptions = genai.HTTPOptions{\n\t\tHeaders: http.Header{\n\t\t\t\"User-Agent\": []string{ua},\n\t\t},\n\t}\n\n\t// Create new Gemini API client\n\tclient, err := genai.NewClient(ctx, configs)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/embeddingmodels/gemini/gemini.go#L79-L115","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set apiKey in the gemini embeddingModel config YAML, or export GOOGLE_API_KEY (or GEMINI_API_KEY)","For Vertex AI, set project and location in YAML or GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION env vars","Verify the env vars are visible to the actual process (echo inside the container/service)","Confirm no typos in env var names and that .env files are loaded","Refer to https://mcp-toolbox.dev/documentation/configuration/embedding-models/gemini/"],"exampleFix":"// before\nembeddingModels:\n  my-embedding:\n    kind: gemini\n    model: text-embedding-004\n// after\nembeddingModels:\n  my-embedding:\n    kind: gemini\n    model: text-embedding-004\n    apiKey: ${GOOGLE_API_KEY}","handlingStrategy":"validation","validationCode":"func hasGeminiCreds(apiKey, project string) error {\n    if apiKey != \"\" || os.Getenv(\"GOOGLE_API_KEY\") != \"\" || os.Getenv(\"GEMINI_API_KEY\") != \"\" {\n        return nil\n    }\n    if project != \"\" || os.Getenv(\"GOOGLE_CLOUD_PROJECT\") != \"\" {\n        return nil\n    }\n    return errors.New(\"gemini embedding: no apiKey or Vertex project/location configured\")\n}","typeGuard":null,"tryCatchPattern":"model, err := cfg.Initialize(ctx)\nif err != nil && strings.Contains(err.Error(), \"missing credentials for Gemini embedding\") {\n    cfg.ApiKey = os.Getenv(\"GOOGLE_API_KEY\")\n    model, err = cfg.Initialize(ctx)\n}","preventionTips":["Set GOOGLE_API_KEY (or GEMINI_API_KEY) in every deployment environment","For Vertex AI, always configure project and location (YAML or env)","Fail fast at startup with a pre-flight credential check","Ensure .env/secrets are actually mounted in containers (verify with env inside the runtime)","Keep the docs URL handy: mcp-toolbox.dev gemini embedding docs"],"tags":["go","gemini","embedding","credentials","env-vars"],"backgroundTag":"missing-credentials","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}