Class: ActionAgent::ProviderKey

Inherits:
ApplicationRecord show all
Includes:
Ownable
Defined in:
app/models/action_agent/provider_key.rb

Overview

Per-account LLM provider credential (Settings -> Provider API Keys). Generation runs (AgentExecutionService and the evaluation LLM judge) prefer these over the platform's ENV-configured keys, so users can run agents with their own OpenAI/Anthropic/OpenRouter accounts — or point ollama at their own host (e.g. a tunnel to a locally running instance).

The credential is encrypted at rest with Active Record Encryption. API keys are never rendered back to the client — only a masked hint; ollama hosts are not secret and are shown in full (see #display_hint).

Constant Summary collapse

KEY_PROVIDERS =

Providers that authenticate with an API key.

%w[openai anthropic openrouter].freeze
HOST_PROVIDERS =

Providers addressed by host URL instead of a key.

%w[ollama].freeze
PROVIDERS =
(KEY_PROVIDERS + HOST_PROVIDERS).freeze

Constants included from Ownable

Ownable::CLASS_FOR

Instance Method Summary collapse

Methods included from Ownable

#owner, #owner=

Methods inherited from ApplicationRecord

for_owner, owner_association

Instance Method Details

#display_hintObject

"sk-a…Q2z9" for keys; hosts are shown in full.



44
45
46
47
48
# File 'app/models/action_agent/provider_key.rb', line 44

def display_hint
  return credential if host_based?

  "#{credential.first(4)}#{credential.last(4)}"
end

#generation_optionsObject

Options merged into generate_with for runs owned by this key's owner, overriding the host app's config/active_agent.yml credentials.



39
40
41
# File 'app/models/action_agent/provider_key.rb', line 39

def generation_options
  host_based? ? { host: credential } : { access_token: credential }
end

#host_based?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/action_agent/provider_key.rb', line 33

def host_based?
  HOST_PROVIDERS.include?(provider)
end