Skip to content

fix(opik_client): make OPIK_API_KEY optional for self-hosted backends#150

Merged
alexkuzmik merged 2 commits into
mainfrom
aliaksandrk/optional-opik-api-key
Jun 25, 2026
Merged

fix(opik_client): make OPIK_API_KEY optional for self-hosted backends#150
alexkuzmik merged 2 commits into
mainfrom
aliaksandrk/optional-opik-api-key

Conversation

@alexkuzmik

Copy link
Copy Markdown
Contributor

Problem

resolve_opik_config has hard-required OPIK_API_KEY since the Python rewrite (a52a687). A self-hosted Opik typically runs with auth disabled and authorizes on the Comet-Workspace header alone, but opik-mcp errors out — OPIK_API_KEY (or an inbound Authorization header) is required to call Opik RESTbefore issuing any request, so it can't be used against a local/OSS backend without inventing a dummy key.

Fix

Make the API key optional, mirroring the workspace handling that main already made optional (DEFAULT_WORKSPACE fallback):

  • resolve_opik_config: drop the missing-key raise; return api_key as str | None.
  • OpikClient.__init__ / _headers: accept an optional key and send the Authorization header only when present.
  • When no key (and no inbound Authorization header) is set, requests go out with just the workspace header and the backend decides — a hosted Opik still rejects with 401, surfaced as a normal request error.

ask_ollie is intentionally left untouched: it targets the hosted Comet endpoint and still requires a key via require_ollie_config.

Tests

  • Flipped the two key-required tests to assert the new keyless behavior (resolve_opik_config returns api_key=None; _headers omits Authorization).
  • Full suite green: 1067 passed, 2 skipped; ruff check, ruff format --check, and mypy all clean.
  • Functional check against a local self-hosted backend (auth disabled), no key set: list_projects and get_trace succeed over both :5173/api and :8080.

🤖 Generated with Claude Code

alexkuzmik and others added 2 commits June 24, 2026 12:03
resolve_opik_config has hard-required OPIK_API_KEY since the Python
rewrite, so opik-mcp cannot talk to a self-hosted Opik that runs with
auth disabled and authorizes on the Comet-Workspace header alone — it
errors before issuing any request.

Make the key optional, mirroring the workspace handling that is already
optional: when no key (and no inbound Authorization header) is present,
requests go out without an Authorization header and the backend decides
(a hosted Opik still rejects with 401, surfaced as a normal request
error). ask_ollie still requires a key, since it targets the hosted
Comet endpoint.

- resolve_opik_config: drop the missing-key raise; return api_key | None
- OpikClient.__init__ / _headers: api_key optional; send Authorization
  only when present
- tests: flip the two key-required tests to assert keyless behavior

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lock in the no-regression case: when a key is genuinely required (hosted
backend) but not configured, the request is still attempted with no
Authorization header and the backend's 401 surfaces as a typed
OpikAuthError — no silent success, hang, or raw crash.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alexkuzmik alexkuzmik merged commit 2c190d4 into main Jun 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants