summaryrefslogtreecommitdiff
path: root/internal/cli/apikeys.go
blob: 0bcaa49c5ef9fbe9a4d1ebefee6899ce4e04ea96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cli

import (
	"os"

	"github.com/spf13/viper"
)

// GetOpenAIKey retrieves the OpenAI API key from environment or config
func GetOpenAIKey() string {
	// First check environment variable
	if key := os.Getenv("OPENAI_API_KEY"); key != "" {
		return key
	}

	// Then check config file
	return viper.GetString("audio.openai_key")
}

// GetGoogleAPIKey retrieves the Google API key from GOOGLE_API_KEY or config.
// It prefers image.google_api_key and falls back to google.api_key for older configs.
func GetGoogleAPIKey() string {
	// First check environment variable
	if key := os.Getenv("GOOGLE_API_KEY"); key != "" {
		return key
	}

	// Then check config file
	if key := viper.GetString("image.google_api_key"); key != "" {
		return key
	}

	// Fall back to the legacy key for compatibility with older configs.
	return viper.GetString("google.api_key")
}