AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
Support organisation-scoped Anthropic API keys
Claudef83714806bdb
diff --git a/.env.example b/.env.exampleindex 10fddeb6..84dbbcca 100644--- a/.env.example+++ b/.env.example@@ -3,6 +3,11 @@# be configured or the app refuses to start.ANTHROPIC_API_KEY=sk-ant-your-key-here+# Only for a key issued at the ORGANISATION level rather than inside a+# workspace. Those keys are rejected with HTTP 400 unless every request carries+# the workspace id. Leave unset for a workspace-scoped key.+# ANTHROPIC_WORKSPACE_ID=+# --- Auth (UI: Auth.js / NextAuth v5 with Google) -----------------------------# Generate AUTH_SECRET with: openssl rand -base64 32# AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRET come from a Google Cloud OAuth Clientdiff --git a/README.md b/README.mdindex 68344e0f..e1cadf45 100644--- a/README.md+++ b/README.md@@ -256,6 +256,7 @@ the app refuses to start.| Variable | Required | Default | Description ||---|---|---|---|| `ANTHROPIC_API_KEY` | Yes¹ | — | Anthropic API key |+| `ANTHROPIC_WORKSPACE_ID` | No | — | Required only for an organisation-scoped Anthropic key; sent as the `anthropic-workspace-id` header. Workspace-scoped keys need no value || `DEFAULT_MODEL` | No | `claude-sonnet-5` | Executive + most specialists || `DEEP_REASONING_MODEL` | No | `claude-opus-5` | CSO, CFO, GC, Board || `VECTOR_STORE_PATH` | No | `./chroma_db` | ChromaDB directory |diff --git a/packages/core/openexecutive/config.py b/packages/core/openexecutive/config.pyindex 58c74ee5..2ba57059 100644--- a/packages/core/openexecutive/config.py+++ b/packages/core/openexecutive/config.py@@ -88,6 +88,11 @@ class Settings(BaseSettings):# registry raises an actionable error if a Claude model is requested# while this is unset.anthropic_api_key: str | None = Field(None, alias="ANTHROPIC_API_KEY")+ # Required only for a key issued at the ORGANISATION level rather than+ # inside a workspace: Anthropic rejects those calls with HTTP 400 unless+ # the request carries an `anthropic-workspace-id` header (#128). A+ # workspace-scoped key needs no value here.+ anthropic_workspace_id: str | None = Field(None, alias="ANTHROPIC_WORKSPACE_ID")default_model: str = Field("claude-sonnet-5", alias="DEFAULT_MODEL")deep_reasoning_model: str = Field("claude-opus-5", alias="DEEP_REASONING_MODEL")diff --git a/packages/core/openexecutive/providers/anthropic_provider.py b/packages/core/openexecutive/providers/anthropic_provider.pyindex 957d28ad..ce4dd1ab 100644--- a/packages/core/openexecutive/providers/anthropic_provider.py+++ b/packages/core/openexecutive/providers/anthropic_provider.py@@ -14,10 +14,22 @@ class AnthropicProvider:is async-safe and pools its own httpx connections."""- def __init__(self, *, api_key: str, timeout: float | None = None) -> None:+ def __init__(+ self,+ *,+ api_key: str,+ timeout: float | None = None,+ workspace_id: str | None = None,+ ) -> None:kwargs: dict[str, Any] = {"api_key": api_key}if timeout is not None:kwargs["timeout"] = timeout+ if workspace_id:+ # An organisation-scoped key carries no workspace of its own, so+ # Anthropic 400s every call without this header. Set as a default+ # header rather than per-request: it applies to create and stream+ # alike, and every Claude call in the app comes through here.+ kwargs["default_headers"] = {"anthropic-workspace-id": workspace_id}self._client = anthropic.AsyncAnthropic(**kwargs)def messages_create(self, **kwargs: Any) -> Awaitable[Any]:diff --git a/packages/core/openexecutive/providers/registry.py b/packages/core/openexecutive/providers/registry.pyindex 814d36a4..c5e9c62d 100644--- a/packages/core/openexecutive/providers/registry.py+++ b/packages/core/openexecutive/providers/registry.py@@ -287,7 +287,10 @@ def _anthropic() -> AnthropicProvider:"at a configured local model."),)- _anthropic_provider = AnthropicProvider(api_key=api_key)+ _anthropic_provider = AnthropicProvider(+ api_key=api_key,+ workspace_id=getattr(settings, "anthropic_workspace_id", None),+ )return _anthropic_providerdiff --git a/packages/core/tests/unit/test_anthropic_workspace_id.py b/packages/core/tests/unit/test_anthropic_workspace_id.pynew file mode 100644index 00000000..11d6bb7c--- /dev/null+++ b/packages/core/tests/unit/test_anthropic_workspace_id.py@@ -0,0 +1,121 @@+"""Organisation-scoped Anthropic keys need a workspace header (#128).++A key issued inside a workspace carries its own scope. A key issued at the+organisation level does not, and Anthropic rejects every call made with one+unless the request sends `anthropic-workspace-id`. Before this setting existed+the failure surfaced as a generic "internal error" in the UI, because the 400+happens after the SSE stream has already returned 200.++The header is set on the client rather than per request: `create` and `stream`+both need it, and every Claude call in the app resolves through this one+provider.+"""+from __future__ import annotations++import os+from typing import Any++os.environ.setdefault("ANTHROPIC_API_KEY", "sk-test-not-used")++import pytest # noqa: E402++from openexecutive.providers import registry as registry_mod # noqa: E402+from openexecutive.providers.anthropic_provider import AnthropicProvider # noqa: E402++[email protected](autouse=True)+def _reset_singleton() -> Any:+ registry_mod._reset_for_tests()+ yield+ registry_mod._reset_for_tests()+++def _headers(provider: AnthropicProvider) -> dict[str, str]:+ """The default headers the SDK client will send on every request."""+ return dict(provider._client.default_headers)+++def test_workspace_id_is_sent_as_a_default_header() -> None:+ provider = AnthropicProvider(api_key="sk-test", workspace_id="wrkspc_123")++ assert _headers(provider)["anthropic-workspace-id"] == "wrkspc_123"+++def test_no_workspace_id_sends_no_header() -> None:+ """A workspace-scoped key must keep working untouched — sending an empty+ or absent workspace id is not the same as sending none."""+ provider = AnthropicProvider(api_key="sk-test")++ assert "anthropic-workspace-id" not in _headers(provider)+++def test_empty_workspace_id_sends_no_header() -> None:+ """`ANTHROPIC_WORKSPACE_ID=` in a .env file arrives as an empty string, not+ None. Forwarding that would turn a working install into a 400."""+ provider = AnthropicProvider(api_key="sk-test", workspace_id="")++ assert "anthropic-workspace-id" not in _headers(provider)+++def test_the_header_is_purely_additive() -> None:+ """`default_headers` must not displace what the SDK sets for itself.++ Auth and the API version ride in the same mapping, so a construction that+ replaced it rather than adding to it would break every call — and would+ look identical to a working one from the workspace assertions above.+ """+ plain = AnthropicProvider(api_key="sk-test")+ with_ws = AnthropicProvider(api_key="sk-test", workspace_id="wrkspc_123")++ added = set(_headers(with_ws)) - set(_headers(plain))++ assert added == {"anthropic-workspace-id"}+ assert with_ws._client.auth_headers == plain._client.auth_headers+++def test_workspace_id_survives_alongside_a_timeout() -> None:+ provider = AnthropicProvider(api_key="sk-test", timeout=30.0, workspace_id="wrkspc_123")++ assert _headers(provider)["anthropic-workspace-id"] == "wrkspc_123"+ assert provider._client.timeout == 30.0+++def test_registry_passes_the_configured_workspace_id(monkeypatch: pytest.MonkeyPatch) -> None:+ """Guards the wiring end to end, not just the constructor.++ `get_settings()` builds a fresh `Settings` on every call, so this goes+ through the environment exactly as a real `.env` does — patching the+ settings object would prove nothing about a deployment.+ """+ monkeypatch.setenv("ANTHROPIC_WORKSPACE_ID", "wrkspc_from_env")+ monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-test")++ provider = registry_mod._anthropic()++ assert _headers(provider)["anthropic-workspace-id"] == "wrkspc_from_env"+++def test_registry_sends_no_header_when_the_var_is_unset(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.delenv("ANTHROPIC_WORKSPACE_ID", raising=False)+ monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-test")++ provider = registry_mod._anthropic()++ assert "anthropic-workspace-id" not in _headers(provider)+++def test_settings_reads_the_var_from_the_environment(monkeypatch: pytest.MonkeyPatch) -> None:+ """The alias has to match what operators put in `.env`."""+ from openexecutive.config import get_settings++ monkeypatch.setenv("ANTHROPIC_WORKSPACE_ID", "wrkspc_alias_check")++ assert get_settings().anthropic_workspace_id == "wrkspc_alias_check"+++def test_settings_default_is_none(monkeypatch: pytest.MonkeyPatch) -> None:+ from openexecutive.config import get_settings++ monkeypatch.delenv("ANTHROPIC_WORKSPACE_ID", raising=False)++ assert get_settings().anthropic_workspace_id is None