Documentation
¶
Overview ¶
Package settings provides unified storage for lokit user settings, including authentication credentials.
All settings are stored in the XDG data directory:
$XDG_DATA_HOME/lokit/ (default: ~/.local/share/lokit/)
Files stored:
- auth.json — Authentication credentials (OAuth tokens and API keys)
Auth.json format: The file is a JSON object keyed by provider ID, where each value is a discriminated union on the "type" field:
- "oauth" — OAuth tokens (copilot, gemini, openai)
- "api" — API keys (google, groq, opencode, openai, custom-openai)
File permissions are 0600 (owner read/write only).
Lookup order for API keys:
- --api-key flag (highest priority)
- Provider-specific environment variable (GOOGLE_API_KEY, GROQ_API_KEY, etc.)
- This credential store
Index ¶
- func DataDir() (string, error)
- func EnvVarForProvider(providerID string) string
- func FilePath() string
- func GetAPIKey(providerID string) string
- func GetBaseURL(providerID string) string
- func MaskKey(key string) string
- func Remove(providerID string) error
- func RemoveAll() error
- func ResolveAPIKey(providerID, flagKey string) string
- func Save(store Store) error
- func Set(providerID string, info *Info) error
- func SetAPIKey(providerID, key string) error
- func SetAPIKeyWithBaseURL(providerID, key, baseURL string) error
- func SetOAuth(providerID, access, refresh string, expires int64, accountID string) error
- type Info
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DataDir ¶
DataDir returns the lokit data directory path. Default: ~/.local/share/lokit (or $XDG_DATA_HOME/lokit).
func EnvVarForProvider ¶ added in v0.4.0
EnvVarForProvider returns the standard environment variable name used to supply an API key for the given provider. Returns empty string for OAuth-only providers (copilot, gemini) and Ollama (no key needed).
Lookup order used by ResolveAPIKey:
- --api-key flag
- Provider-specific env var (e.g. GOOGLE_API_KEY)
- Stored credential from auth.json
func FilePath ¶
func FilePath() string
FilePath returns the auth.json file path for display purposes.
func GetAPIKey ¶
GetAPIKey retrieves the stored API key for a provider. Returns empty string if not found or not an API key entry.
func GetBaseURL ¶
GetBaseURL retrieves the stored base URL for a provider. Returns empty string if not found.
func ResolveAPIKey ¶ added in v0.4.0
ResolveAPIKey returns the effective API key for a provider, following the standard priority order:
- flagKey — value from --api-key flag (if non-empty, returned as-is)
- Provider-specific env var (e.g. GOOGLE_API_KEY, GROQ_API_KEY)
- Stored credential from auth.json
func SetAPIKeyWithBaseURL ¶
SetAPIKeyWithBaseURL stores an API key and base URL for custom-openai.
Types ¶
type Info ¶
type Info struct {
// Type discriminator: "oauth" or "api"
Type string `json:"type"`
// OAuth fields (type == "oauth")
Access string `json:"access,omitempty"`
Refresh string `json:"refresh,omitempty"`
Expires int64 `json:"expires,omitempty"` // Unix timestamp (0 = no expiry)
// Gemini-specific OAuth fields
Email string `json:"email,omitempty"` // Google account email
ProjectID string `json:"projectId,omitempty"` // Code Assist project ID
// OpenAI-specific OAuth fields
AccountID string `json:"accountId,omitempty"` // ChatGPT account or organization ID
// API key fields (type == "api")
Key string `json:"key,omitempty"`
// Custom endpoint URL (openai/custom-openai)
BaseURL string `json:"baseUrl,omitempty"`
}
Info is the discriminated union stored per provider in auth.json. Exactly matches OpenCode's Auth.Info shape.