Skip to content

feat(client-contract): add the invalid_api_key proxy code - #57

Open
sefk wants to merge 1 commit into
devfrom
feat/invalid-api-key-code
Open

sefk wants to merge 1 commit into
devfrom
feat/invalid-api-key-code

Conversation

@sefk

@sefk sefk commented Nov 16, 2026

Copy link
Copy Markdown

Summary

The website's platform proxy now accepts API keys (Authorization: Bearer dfo_... or X-API-Key). A call whose key is unknown, revoked or malformed is refused with a 401 problem document, not served as an anonymous call. That document carries the code invalid_api_key, which proxy-codes.json did not list, so the document's type fell back to about:blank and /codes/invalid_api_key did not resolve.

  • proxy-codes.json gains invalid_api_key (401), sorted before rate_limited. format_version stays 1: a code is added, and no field changes.
  • Unlike the two existing proxy codes, this refusal is not retryable. tools/validate_client_contract.py required retryable: true of every proxy problem document in a scenario, so it now expects retryable: false for invalid_api_key and true for the rest, and a test pins both.
  • The conflicting-keys refusal (a bearer and an X-API-Key that carry different keys) answers 400 with the registry's existing request_invalid, so it needs no contract change.
  • CHANGELOG.md for client-contract has an entry under Unreleased.

A client reads the 401 through the status fallback as AuthenticationError and carries the code. No scenario changes.

Part of DevelopmentFinanceObservatory/website#142. The website vendors this file in DevelopmentFinanceObservatory/website#143.

Test plan

  • uv run tools/validate_client_contract.py
  • uv run --with jsonschema --with pyarrow --with pytest pytest tools/tests -q, including the new test_an_invalid_api_key_problem_is_not_retryable
  • In python/client-contract: uv run pytest, uv run ruff check ., uv run ruff format --check ., uv run ty check src/dfo_client_contract

🤖 Generated with Claude Code

https://claude.ai/code/session_015QQk2mKJZzXv2AYykDjvQf

The website proxy answers a call whose API key is unknown, revoked or
malformed with a 401 problem document carrying `invalid_api_key`, and does
not fall back to anonymous access. List it in proxy-codes.json so the
document's type resolves to a code page.

Unlike rate_limited and transient_unavailable the refusal is not retryable,
so validate_client_contract.py now expects `retryable: false` in a proxy
problem document with this code and `retryable: true` in any other.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QQk2mKJZzXv2AYykDjvQf

This branch has not been deployed

No deployments
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.

1 participant