HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
feat(images): image generation through the model broker, no key in the sandbox
richard-epsilla3d11b2bfc7e9
diff --git a/Dockerfile b/Dockerfileindex 7e2652d1..e246f0b7 100644--- a/Dockerfile+++ b/Dockerfile@@ -110,11 +110,16 @@ ENV HR_BUILTIN_SKILLS_DIR=/opt/harnessrouter/skills# the right trade for a document a person is going to open.ENV OFFICECLI_RESIDENT_FLUSH=eachCOPY docker/install-skills.sh /tmp/install-skills.sh+# Cache-bust the clone below. Without this the RUN layer is keyed only on the script, so a build+# that pulls `main` keeps whatever catalogue the first build happened to fetch — new skills never+# ship, and nothing says so. This ADD fetches the branch head, so the layer's inputs change+# exactly when the skills repo does.+ADD https://api.github.com/repos/HarnessRouter/skills/commits/${HR_SKILLS_REF} /tmp/skills-head.jsonRUN chmod +x /tmp/install-skills.sh \&& WITH_BUILTIN_SKILLS="$WITH_BUILTIN_SKILLS" HR_SKILLS_REPO="$HR_SKILLS_REPO" \HR_SKILLS_REF="$HR_SKILLS_REF" HR_SKILLS_DIR=/opt/harnessrouter/skills \/tmp/install-skills.sh \- && rm -f /tmp/install-skills.sh+ && rm -f /tmp/install-skills.sh /tmp/skills-head.jsonCOPY gateway/ /app/gateway/COPY runner/ /app/runner/diff --git a/gateway/app.py b/gateway/app.pyindex 69d9450b..88940fb0 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -949,6 +949,38 @@ async def _effective_model_map() -> dict[str, str]:return mm+async def _image_auth(sid: str, backend: str) -> dict | None:+ """Broker credentials for image generation, or None when no integration can serve an image+ model. Same shape as the chat auth: a per-turn credential and the broker's base_url, never a+ provider key — the sandbox calls us and we hold the secret.++ Resolved independently of the turn's chat connection because they are usually different+ providers: a Claude Code harness runs on Anthropic, which has no image API, so reusing the+ turn's credential would relay /images/generations to Anthropic and 404.+ """+ # PUBLIC_BASE_URL is deliberately NOT required: that is a precondition of the BROKER hop, and+ # self-hosted owner mode has no hop — _auth_from_conn hands back the operator's own key for+ # their own box. Requiring it here made image generation report "not configured" on exactly+ # the deployment where it needs no configuration at all. Let _auth_from_conn decide what is+ # safe to hand over; it returns None when the answer is nothing.+ if not sid or (SANDBOX_TRUST != "owner" and not HR_BROKER_IMAGES):+ return None+ for integ in await _integrations_doc():+ vendor = (integ.get("provider") or "").strip().lower()+ table = _IMAGE_VENDOR_MODELS.get(vendor)+ if not table:+ continue+ provider = _INTEGRATION_WIRING.get((vendor, backend)) or vendor+ conn = {"name": f"integration:{integ.get('name') or ''}", "backend": backend,+ "provider": provider,+ **{k: v for k, v in (integ.get("config") or {}).items() if v not in (None, "")}}+ auth = _auth_from_conn(conn, sid)+ if auth and auth.get("base_url") and auth.get("api_key"):+ model = next(iter(table))+ return {"base_url": auth["base_url"], "api_key": auth["api_key"], "model": model}+ return None++async def _mapped_integration_conn(backend: str, canonical: str) -> dict | None:"""The synthetic connection for a model→integration mapping, or None when unmapped /unusable by this backend. Shaped exactly like a vault connection so the turn loop treats@@ -2269,12 +2301,23 @@ _BROKER_ALLOWED_EXACT = {"messages", "messages/count_tokens", "responses", "chat_BROKER_ALLOWED_PREFIX = ("responses/", "models/", "messages/batches")HR_BROKER_PATHS = os.environ.get("HR_BROKER_PATHS", "enforce").strip().lower()+# Image generation rides the same broker as chat, so a task never holds a provider key. It is a+# SEPARATE switch because the money works differently: this relay does not meter, and image APIs+# bill per image rather than per token, so a deployment spending its OWN key must count images+# before opening this. Self-hosted is bring-your-own-key — the operator is spending their own+# money and there is nothing to meter — so it defaults ON there and a hosted deployment sets+# HR_BROKER_IMAGES=0 until its metering lands.+_BROKER_IMAGE_PATHS = {"images/generations", "images/edits", "images/variations"}+HR_BROKER_IMAGES = os.environ.get("HR_BROKER_IMAGES", "1").strip().lower() not in ("0", "off", "false")+def _broker_path_allowed(suffix: str) -> bool:"""True if this upstream path is part of the inference surface."""s = (suffix or "").strip("/").lower()if not s or ".." in s: # empty or traversal — never forward our credentialreturn False+ if s in _BROKER_IMAGE_PATHS:+ return HR_BROKER_IMAGESreturn s in _BROKER_ALLOWED_EXACT or s.startswith(_BROKER_ALLOWED_PREFIX)@@ -3709,6 +3752,16 @@ _VENDOR_MODELS: dict[str, dict[str, str]] = {_TOKENROUTER_NO_CHANNEL = {"minimax-m3", "nemotron-3-ultra", "hunyuan-3", "ling-3.0-flash", "qwen3.7-flash",}+# Image models, kept OUT of _VENDOR_MODELS on purpose: those tables feed the chat model pickers+# and the per-backend catalogs, and an image model offered as a chat model is a broken choice a+# user can make. Canonical → provider id, same shape, resolved by _image_auth only.+_IMAGE_VENDOR_MODELS: dict[str, dict[str, str]] = {+ "openai": {"gpt-image-1": "gpt-image-1", "gpt-image-1-mini": "gpt-image-1-mini"},+ "azure": {"gpt-image-1": "gpt-image-1"},+ "azure-foundry": {"gpt-image-1": "gpt-image-1"},+}++_VENDOR_MODELS["tokenrouter"] = {c: v for c, v in _VENDOR_MODELS["openrouter"].items()if c not in _TOKENROUTER_NO_CHANNEL}@@ -4148,6 +4201,8 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, smapped_conn = await _mapped_integration_conn(backend, model_req)candidates: list[tuple[str, dict | None]] = ([(mapped_conn["name"], mapped_conn)] if mapped_conn else [])candidates += [(n, None) for n in chain]+ # Independent of which chat connection wins below: images are usually a different provider.+ image_auth = await _image_auth(sid, backend)for name, pre in candidates:conn, src = (pre, "integration") if pre is not None else await _get_connection(org, name)if not conn:@@ -4177,6 +4232,9 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, s"auth": sandbox_auth, "resume_session_id": resume, "files": files_in,"mcp_servers": mcp_servers, "skills": skills, "agent_doc": agent_doc,"skills_suppressed": skills_suppressed, "tools_disabled": tools_disabled,+ # Image generation, when an integration can serve it. A per-turn credential for+ # the broker, never a provider key — see _image_auth.+ "image_auth": image_auth,# idempotency: all _sandbox_json retries of THIS turn share the response id, so a# lost/slow first reply that gets retried dedups to the same runner turn (no re-exec)."idempotency_key": f"{translator.resp_id}:{name}",diff --git a/runner/server.py b/runner/server.pyindex 50d5e7a3..533bbd99 100644--- a/runner/server.py+++ b/runner/server.py@@ -1927,6 +1927,7 @@ class TurnReq(BaseModel):agent_doc: str | None = None # harness instruction doc → AGENTS.md (codex) / CLAUDE.md (claude)skills_suppressed: list[str] | None = None # built-in skill names to NOT mount (harness disabled them)tools_disabled: list[str] | None = None # built-in tool names to disable (claude: --disallowedTools)+ image_auth: dict | None = None # {base_url, api_key, model} for image generation via the brokeridempotency_key: str = "" # dedup a retried /turn: same key -> same turn, no re-execpartial_messages: bool = False # claude: stream token-level deltas (--include-partial-messages)codex_appserver: bool = False # codex: run via app-server (streams item/agentMessage/delta)@@ -1986,6 +1987,17 @@ def turn(req: TurnReq, identifier: str = "") -> dict:f"## Disabled tools\n\nDo NOT use these tools — they are disabled for this harness: {_off}."_write_agent_doc(cwd, backend, agent_doc, installed_skills)env = os.environ.copy()+ # Image generation. Deliberately NOT the OPENAI_* names: on a codex harness those already+ # point at the CHAT connection, which is often a different provider, and one env pair can+ # only carry one credential. The imagegen skill's wrapper reads these and passes them to the+ # SDK explicitly, so images work the same on every base. The value is a per-turn broker+ # credential, never a provider key.+ if req.image_auth:+ for k, v in (("HR_IMAGE_BASE_URL", req.image_auth.get("base_url")),+ ("HR_IMAGE_KEY", req.image_auth.get("api_key")),+ ("HR_IMAGE_MODEL", req.image_auth.get("model"))):+ if v:+ env[k] = str(v)# CRITICAL for resume: both CLIs write their conversation transcripts under $HOME# (~/.claude/projects/*.jsonl, ~/.codex/sessions/*) — NOT under CLAUDE_CONFIG_DIR. The default# $HOME is outside /workspace, so transcripts were never checkpointed and `--resume` found nothing