provider

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package provider is the pure logic behind brokered agent runners: which gateway environment a model provider needs in the agent pod, and how canonical model ids translate to the provider-specific ids the CLI's --model flag expects there. Two harnesses are brokered:

  • claude (anthropic, bedrock, vertex, foundry), configured through the claude CLI's own base-URL and skip-auth env;
  • codex (openai, azure), configured through a rendered config.toml that declares a custom model provider at the broker.

Canonical ids ("anthropic/claude-sonnet-5") stay canonical everywhere controller-side (CRDs, allowlists, pricing). Translation happens in-pod at agentrun's cliModel, fed by the PATCHY_MODEL_MAP this package renders. The per-provider derived defaults (Bedrock's region-prefixed ids, Vertex's bare ids) mean operators only write a model map for Foundry or Azure, whose deployment names cannot be derived, or to override a default.

Index

Constants

View Source
const (
	CodexConfigEnv         = "PATCHY_CODEX_CONFIG"
	BrokerTokenEnv         = "PATCHY_BROKER_TOKEN"
	CodexPlaceholderKeyEnv = "PATCHY_BROKER_API_KEY"
)

The codex CLI has no env-only channel for a custom request header the way claude has ANTHROPIC_CUSTOM_HEADERS, and its built-in openai provider cannot be extended. A brokered codex run therefore selects a custom model provider declared in config.toml (written in-pod from CodexConfigEnv to ${CODEX_HOME:-$HOME/.codex}/config.toml). Its base_url is the broker's route and its headers are read from the child process's env at request time:

  • BrokerTokenEnv carries the projected caller token, sent as BrokerTokenHeader (env_http_headers). Set per stage, never on the pod.
  • CodexPlaceholderKeyEnv carries BrokerAuthPlaceholder as the provider's env_key, so codex has an "API key" and sends Authorization: Bearer patchy-egress-broker. The broker strips it before injecting the real credential; like claude's placeholder it grants nothing.
View Source
const (
	BrokerAuthPlaceholderEnv = "ANTHROPIC_AUTH_TOKEN"
	BrokerAuthPlaceholder    = "patchy-egress-broker"
)

The claude CLI's first-party route refuses to send any request ("Not logged in · Please run /login") unless one of its credential channels is set. Unlike bedrock/vertex/foundry, it has no CLAUDE_CODE_SKIP_*_AUTH switch. A brokered anthropic run therefore presents this fixed, non-secret stand-in on the child process's env (never the pod spec, which stays credential-free). The broker strips Authorization before injecting the real credential, so the value never leaves the cluster and grants nothing.

View Source
const (
	Anthropic = "anthropic"
	Bedrock   = "bedrock"
	Vertex    = "vertex"
	Foundry   = "foundry"
	OpenAI    = "openai"
	Azure     = "azure"
)

Provider names: the model APIs a brokered runner can front. The first four serve the claude harness, the last two the codex harness.

View Source
const BrokerTokenHeader = "X-Patchy-Broker-Token"

BrokerTokenHeader carries the agent pod's projected ServiceAccount token to the egress broker; the broker validates it via TokenReview and strips it before any byte is forwarded upstream. It is defined here, the one package both the in-pod runtime and the broker import, so the two sides can never drift.

Variables

View Source
var CodexNames = []string{OpenAI, Azure}

CodexNames lists the valid codex provider names, in display order.

View Source
var GatewayEnvNames = []string{
	"ANTHROPIC_BASE_URL",
	"ANTHROPIC_BEDROCK_BASE_URL",
	"ANTHROPIC_VERTEX_BASE_URL",
	"ANTHROPIC_FOUNDRY_BASE_URL",
	"CLAUDE_CODE_USE_BEDROCK",
	"CLAUDE_CODE_USE_VERTEX",
	"CLAUDE_CODE_USE_FOUNDRY",
	"CLAUDE_CODE_SKIP_BEDROCK_AUTH",
	"CLAUDE_CODE_SKIP_VERTEX_AUTH",
	"CLAUDE_CODE_SKIP_FOUNDRY_AUTH",
	"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
	"ANTHROPIC_CUSTOM_HEADERS",
	"ANTHROPIC_VERTEX_PROJECT_ID",
	"CLOUD_ML_REGION",
	"AWS_REGION",
	"PATCHY_BROKER_TOKEN_FILE",
	"PATCHY_MODEL_MAP",
	CodexConfigEnv,
	BrokerTokenEnv,
	CodexPlaceholderKeyEnv,
}

GatewayEnvNames are the agent-pod env names this package owns. internal/jobs reserves all of them so controller-global env can never shadow a gateway value, and ExtraEnv may not name them either.

Names lists the valid claude provider names, in display order.

Functions

func CodexConfig added in v0.14.0

func CodexConfig(c Config) string

CodexConfig renders the config.toml a brokered codex run uses: the custom broker provider (Responses API at <broker>/<route>/v1), with the update check, analytics and feedback uploads off. The broker is the pod's only egress and proxies model traffic alone. This is the codex analogue of claude's CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC.

func EffectiveModelMap

func EffectiveModelMap(c Config, models []model.Model) (map[string]string, error)

EffectiveModelMap resolves the canonical→CLI-id map the pod translates with: a derived default per registry model the claude harness can run, overridden by the operator's entries. The first-party providers (anthropic, openai) need no translation because the registry already carries their CLIs' ids, and foundry and azure have no derivable defaults, so all four return a copy of cfg.ModelMap.

func Env

func Env(c Config, modelMap map[string]string) map[string]string

Env renders the agent-pod gateway environment for the provider: for claude, the base-URL override pointing the CLI at the broker's provider route, the skip-auth switches (the broker owns the credential) and the provider's own context vars; for codex, the rendered config.toml (CodexConfig). Either way it adds the rendered model map and the ExtraEnv passthrough. modelMap is the effective canonical→CLI-id map (EffectiveModelMap).

func FormatModelMap

func FormatModelMap(m map[string]string) string

FormatModelMap renders a model map as the PATCHY_MODEL_MAP wire form: comma-joined canonical=cliID pairs, sorted for determinism.

func NamesFor added in v0.14.0

func NamesFor(harnessID string) []string

NamesFor lists the valid provider names for a harness.

func ParseModelMap

func ParseModelMap(s string) (map[string]string, error)

ParseModelMap parses the PATCHY_MODEL_MAP wire form back into a map. It is the single codec both sides share; a malformed entry is an error, not a silently dropped translation.

func ValidateCoverage

func ValidateCoverage(c Config, models []model.Model, modelMap map[string]string, required []string) error

ValidateCoverage fails when a required canonical model (allowlist entries, stage defaults) that the config's harness would run has no entry in the effective map. Only foundry and azure can under-cover, since their maps are entirely operator-written, but the check is provider-agnostic so a future gap surfaces at startup rather than mid-run.

Types

type Config

type Config struct {
	// Harness is the harness the runner drives: claude (the default when
	// empty) or codex. It selects the valid provider names and how the
	// gateway env is rendered.
	Harness string
	// Name is the provider: anthropic, bedrock, vertex, or foundry for
	// claude; openai or azure for codex.
	Name string
	// BrokerURL is the egress broker's base URL; the per-provider route
	// (/anthropic, /bedrock, /openai, ...) is appended. Always required,
	// because brokered is the only mode a claude or codex runner has.
	BrokerURL string
	// Region is the provider region: required for bedrock (SigV4 scope and
	// the AWS_REGION the CLI sends) and vertex (CLOUD_ML_REGION).
	Region string
	// RegionPrefix overrides the Bedrock inference-profile prefix derived
	// from Region (us/eu/apac) for regions the derivation cannot cover.
	RegionPrefix string
	// ProjectID is the GCP project Vertex requests bill to; vertex only.
	ProjectID string
	// ModelMap maps canonical model ids to provider-specific CLI ids,
	// overriding the derived defaults. Foundry and Azure have no derivable
	// defaults (deployment names are operator-chosen), so there it is the
	// whole map.
	ModelMap map[string]string
	// ExtraEnv is operator passthrough into the agent pod's gateway env.
	// Credential-named and patchy-owned keys are rejected.
	ExtraEnv map[string]string
}

Config describes one brokered runner's model provider.

func (Config) Validate

func (c Config) Validate() error

Validate rejects a config the gateway env cannot be built from.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL