Module: Ai::OpenRouterOptions

Defined in:
app/services/ai/open_router_options.rb

Overview

The privacy contract for every OpenRouter call Heatwave makes.

It lives in one place because it is a data-protection control, not a tuning
knob: prompts on this gateway carry customer names, revenue and call
transcripts, and open-weight models route to third-party hosts with wildly
different retention policies. A second copy that drifts is a silent leak,
not a bug you'd notice in a test.

Enforcement does not depend on this hash. The API key carries an
account-level ZDR guardrail (doc/development/OPENROUTER.md), and the
per-request zdr flag ORs with it — it can only ADD enforcement, never
relax it. We send it anyway so the requirement is visible at the call site
and still holds if a key is ever provisioned without the guardrail.

Class Method Summary collapse

Class Method Details

.provider_prefs(require_parameters: true) ⇒ Hash

Returns the provider block for with_provider_options.

Parameters:

  • require_parameters (Boolean) (defaults to: true)

    restrict routing to hosts that support
    every parameter sent. Mandatory when the request carries tools — without
    it a host that silently DROPS tools stays eligible, and a tool-free
    turn doesn't error, it fabricates. Pointless on a single-shot text call,
    where it only narrows the pool.

Returns:

  • (Hash)

    the provider block for with_provider_options



26
27
28
29
30
31
32
# File 'app/services/ai/open_router_options.rb', line 26

def self.provider_prefs(require_parameters: true)
  {
    data_collection: 'deny',
    zdr: true,
    require_parameters: require_parameters
  }
end

.single_shot(session_id: nil) ⇒ Hash

Body extensions for a single-shot (tool-free) OpenRouter call.

Parameters:

  • session_id (String, nil) (defaults to: nil)

    sticky-routing pin. Worth sending when
    several calls share a prompt prefix so they land on one host's prompt
    cache; nil for one-off work, where pinning buys nothing.

Returns:

  • (Hash)


40
41
42
# File 'app/services/ai/open_router_options.rb', line 40

def self.single_shot(session_id: nil)
  { provider: provider_prefs(require_parameters: false), session_id: session_id }.compact
end