Worked Examples
Apply versioned api contracts — Sustainable Catalyst Platform Core
Versioned API contracts preserve compatibility across Platform Core requests, responses, errors, and client integrations. This guide covers contract validation, breaking-change detection, SDK compatibility, and controlled upgrades that protect research data and provenance.
Application: Sustainable Catalyst Platform Core
Component: API Contracts & Developer Integration
Status: Source-reviewed technical procedure; deployed verification pending
Estimated reading time: 17–20 minutes
Source baseline: 59b8444365525a58fd4f6a7e29a20d712769e1a2
Summary: Versioned API contracts preserve the meaning of client requests, responses, errors, permissions and research provenance across releases. This guide explains how to capture a baseline, detect incompatible changes and validate old clients before approving a migration.
1. Goal
Ensure that existing clients detect incompatible upgrades and expected error states instead of silently accepting changed behavior. For every supported operation, verify the same HTTP method, path, required inputs, authorization scope, response fields and types, media format, error behavior and scientific semantics. A successful HTTP status alone is not proof of compatibility.
2. Requirements
- Exact source commit, candidate deployment identifier, migration revision and separately pinned client SDK releases.
- Deployed OpenAPI/route inventory, versioned JSON schemas and a reviewed contract manifest, with SHA-256 digests.
- Disposable staging, synthetic data, separately scoped test credentials, and access to sanitized request IDs, status codes and selected response headers.
- Accepted test cases for read, pagination, invalid input, missing rights, expired/revoked credentials, rate limits, downstream failures and scientific provenance.
- Approved backup, rollback and change-control procedure. Never expose credentials, customer identifiers or private research content in a public knowledge-base article.
3. Three different version boundaries
| Boundary | Observed contract | Meaning |
|---|---|---|
| Public HTTP API | /api/v1, X-SC-API-Version: 1, meta.api_version: v1 |
Public major version. Breaking changes require a new major route, not a silent replacement. |
| Internal product API | /v1 route family |
Administrative and product integration with different security and response contracts. |
| Platform release and schema | Service version, versioned schemas/*.schema.json, SDK releases |
Release number and object schema must not be confused with the public HTTP major. |
The repository documents compatible additions within /api/v1 and a new /api/v2 for breaking changes. It does not guarantee that every deployed route, downstream application or older SDK implements the same response envelope. Public API contract.
4. Verify an operation inventory
| Operation | Source-level route | Boundary to test |
|---|---|---|
| Public status | GET /api/v1/status |
public:status; envelope and version header. |
| Entity listing | GET /api/v1/entities |
registry:read; public-only output and pagination. |
| Evidence listing | GET /api/v1/evidence-records |
evidence:read; default verified review state. |
| Gateway health | GET /api/v1/gateway/health |
gateway:read; independent downstream health. |
| STAC catalog | GET /api/v1/stac |
data:read; raw standard STAC JSON, not Core envelope. |
| Internal gateway catalog | GET /v1/gateway/services |
Separate internal write-key dependency; not interchangeable with public key. |
These are source-observed routes, not live availability claims. Record the actual deployed path and method, request and response schema, expected errors, and security scope. If a route is disabled in an environment, mark the test blocked rather than passed.
5. Authentication and permission compatibility
Public clients present an active key through Authorization: Bearer or X-SC-Public-Key. The middleware also checks application approval, active plans, expiration, scope and quota. Scope expansion on an existing route is a contract change even if the JSON response shape is unchanged. Internal operations use different guards; permission to call a public read endpoint is not permission to mutate a project through /v1.
Test the resource endpoint itself with a permitted identity, missing-key identity, wrong-scope identity and revoked key. Do not treat a separate governance evaluation as proof that the route enforces the decision. Inspect public API middleware.
6. Successful response contract
Ordinary public JSON endpoints use a data/meta envelope. A sanitized status response is illustrated below; the deployed release value must be read, not guessed:
{
"data": {
"service": "Sustainable Catalyst Platform Core",
"version": "DEPLOYED_RELEASE",
"status": "operational"
},
"meta": {
"api_version": "v1",
"request_id": "synthetic-request-001",
"documentation": "/developers"
}
}
Verify X-SC-API-Version: 1, X-Request-ID and equality of the response header and meta.request_id. The Pydantic PublicEnvelope provides data and meta; route and middleware logic populate the version fields. Public middleware early returns for a disabled API (404) or missing production request-log salt (503) can precede the usual API-version header assignment; record these as explicit exceptions rather than misclassifying them as a major upgrade.
7. Error contracts are heterogeneous
| HTTP | Representative cause | Client treatment |
|---|---|---|
| 401 | Missing, inactive, invalid or revoked public key | Stop; request authorized authentication. No blind replay. |
| 403 | Missing public scope or inactive app/plan | Report access failure without exposing record existence. |
| 404 | Absent/nonpublic object; some disabled features | Do not assume a resource is permanently removed. |
| 405 / 413 | Disallowed gateway method / excessive body | Change client call only after contract review. |
| 422 | Invalid schema, query or model | Show sanitized validation evidence; no silent coercion. |
| 429 | Minute/day quota exceeded | Respect Retry-After; retry only safe reads. |
| 502 / 503 / 504 | Upstream error, unavailable dependency or timeout | Correlate request ID and downstream health; avoid write replay. |
Auth and standard validation failures may use {"detail": ...}. Gateway JSON errors can use {"data": null, "meta": {...}, "warnings": [...]}, while proxied non-JSON content may pass through with a different media type. Never assume all failures contain data.error. See the gateway response implementation.
8. Breaking-change classification
| Change | Default classification | Acceptance criterion |
|---|---|---|
| Add optional response field | Usually additive | Old client still parses response and ignores unknown property. |
| Remove/rename required field or change type | Breaking | New API major or explicitly versioned adapter and migration. |
| Add required input or scope | Breaking | Old request now rejected; captured negative test. |
| Change pagination, unit, filter default, time zone, sorting or review state | Behavioral breaking change | Semantic fixture and independent scientific assessment. |
| Change error codes or body shape | Requires review; often breaking | Error-handling tests across supported SDKs. |
| Change STAC into Core envelope | Breaking | Standards-based STAC client remains compatible. |
| Add new route without altering old behavior | Usually additive | Old client tests remain green. |
9. Procedure — establish an accepted baseline
- Identify the authoritative repository, exact SHA, supported public major, internal routes, active SDK versions, deployed build and schema/migration head.
- Capture the deployed OpenAPI document with authorized read-only access and store its SHA-256 digest. A checked-in schema alone is not evidence of what is running.
- For each supported operation, record stable operation ID, HTTP method/path, required scopes, request fields, response types, status codes, media type, semantic defaults and public/private data restrictions.
- Capture sanitized success and negative-response examples from disposable staging with explicit request IDs. Preserve a copy of the accepted fixtures.
- Keep the approved baseline unchanged; generate a separate candidate manifest for the proposed release.
The included fixtures/baseline.json is a synthetic, human-maintained teaching fixture, not a generated OpenAPI snapshot. Real release verification must compare an authorized export from the deployed candidate against an approved baseline and explain any exceptional routes.
10. Procedure — verify a real read-only status request
Use an expressly authorized staging endpoint and staging-only public API key. This Python standard-library example sends a single GET and prints no credentials:
import json, os, urllib.request, urllib.error
base = os.environ["SC_CORE_STAGING_URL"].rstrip("/")
key = os.environ["SC_CORE_STAGING_PUBLIC_KEY"]
req = urllib.request.Request(
base + "/api/v1/status", method="GET",
headers={
"Authorization": "Bearer " + key,
"Accept": "application/json",
"X-Request-ID": "kb-contract-readonly-001"
}
)
try:
with urllib.request.urlopen(req, timeout=15) as response:
body = json.load(response)
assert response.status == 200
assert response.headers["X-SC-API-Version"] == "1"
assert body["meta"]["api_version"] == "v1"
assert body["meta"]["request_id"] == response.headers["X-Request-ID"]
assert body["data"]["status"] == "operational"
print("PASS", response.headers["X-Request-ID"])
except urllib.error.HTTPError as error:
print("FAIL HTTP", error.code)
raise
Do not use this as a health assertion for every downstream service; gateway health and version reporting must be checked separately. Do not treat a working status endpoint as permission to read private research objects.
11. Procedure — exercise negative cases safely
In isolated staging, send synthetic requests with: no credential, wrong-scope credential, revoked credential, missing public record, invalid schema and an intentionally low quota. Verify the exact HTTP status, API-version header where applicable, request ID, error-body variant and absence of private output. Existing repository tests exercise 401, 403, 429, revocation and rate-limit headers; they are source evidence, not a newly run staging suite.
Do not force quota exhaustion or generate authentication-failure floods against production. If a write must be tested, use disposable data, an approved idempotency strategy and before/after accepted revision checks.
12. Procedure — run the offline contract comparison
From the downloaded package directory, run:
python3 -m unittest discover -s tests -v
python3 contract_check.py fixtures/baseline.json fixtures/candidate-compatible.json --observation fixtures/observation-success.json
python3 contract_check.py fixtures/baseline.json fixtures/candidate-breaking.json
The compatible fixture reports breaking: 0 and exits successfully. The deliberately incompatible fixture reports breaking changes and exits with status 1; this is an expected negative result. The checker uses the same stable operation IDs to compare route/method, required scopes/parameters/body fields, response types and fields, success codes, media kind and pinned semantic invariants. Adding a response field is allowed, but removing an accepted field is not.
Limit: This is an offline compatibility model, not a full OpenAPI/JSON Schema evaluator. A complete release gate also needs actual OpenAPI generation, SDK tests, authorization probes, version-skew handling and scientific review.
13. Semantic compatibility and research provenance
Pin the interpretation of scientific data in addition to JSON shape: source identity, unit, observation/reference time, time zone, spatial reference system, version or vintage, default filters, null/missing behavior, rights, review status, source links, transformation method and provenance. A route that still returns HTTP 200 may nevertheless be incompatible if it changes a monthly rate to an annual rate, changes source selection without recording it, or includes unverified evidence by default.
{
"operation": "public.evidence.list",
"synthetic": true,
"semantic_guards": {
"public_only": true,
"review_status_default": "verified",
"raw_provider_data_excluded": true
},
"independent_scientific_review": "pending"
}
A machine-readable provenance trail supports reproducibility and accountability, not scientific truth or publication approval. Any change in units, assumptions, evidence visibility or transformation method requires review beyond schema tests.
14. Client SDK compatibility and a concrete regression candidate
The checked-in Python and JavaScript public SDKs prefix request paths with /api/v1 and usually return only payload.data. Their raw-response helpers are necessary when the consumer needs the complete metadata envelope. A source review of backend/public_sdk/javascript/index.mjs also finds selected later helper methods calling this.get(...) with paths already prefixed /api/v1, while that inspected client file defines request(...) and requestRaw(...) but no get method. This is a source-level defect candidate, not a verified production failure.
Test each SDK method against a mocked HTTP client before publishing or upgrading the package. A repair must avoid both an undefined method and a duplicate /api/v1/api/v1 prefix. Do not silently rewrite SDK imports or change method signatures without a versioned release.
// Illustrative path-composition regression test.
function publicUrl(base, relative) {
if (!relative.startsWith("/") || relative.startsWith("/api/v1/")) {
throw new Error("Use a relative path, without the major prefix");
}
return base.replace(/\/$/, "") + "/api/v1" + relative;
}
if (!publicUrl("https://example.invalid", "/status").endsWith("/api/v1/status")) {
throw new Error("Client URL mismatch");
}
15. Gateway and downstream release skew
Core version, the gateway version header and the downstream service release may differ. The checked-in gateway runtime can classify a downstream health check as version_unreported or version_mismatch when an expected version prefix is configured. Also distinguish circuit breakers, non-success upstream status, timeouts and method restrictions. Gateway code does not automatically retry proxied writes because they may not be idempotent.
Before release, compare the configured expected downstream version, actual returned version, permitted HTTP methods, header forwarding and serialized response. Do not assume a green Core status proves Workbench, Lab or other downstream compatibility.
16. Raw-media and standards compatibility
STAC and GeoJSON routes documented under the public API return standards-based documents rather than the Core data/meta wrapper. A generic client wrapper must not force every JSON response into the same envelope or change its content type. Preserve the external data standard and validate with a corresponding standards-aware parser.
17. Migration and rollback sequence
- Freeze accepted OpenAPI/contract artifacts and both client versions.
- Introduce additive fields or dual routes; do not remove supported
/api/v1functionality in place. - If breaking, explicitly version the new major route and support an approved migration window.
- Run isolated unit, integration, permission, negative-case and scientific semantic tests with synthetic fixtures.
- Check migration state, complete off-host backup and verified restore capability, and separately sign off any authorization change.
- Deploy within an approved change window and monitor request IDs, error rates, SDK behavior, gateway version skew and public data leakage.
- On failure, restore the accepted release and reconcile schema migrations only through the reviewed rollback plan.
A Platform Core recovery checkpoint is integrity evidence and metadata; it is not a PostgreSQL backup or a replacement for tested off-host restoration.
18. CI and release acceptance matrix
| Case | Pass condition | Evidence |
|---|---|---|
| Old SDK + candidate | Same required fields, scopes and positive outputs | SDK version, request ID, fixture comparison |
| Missing/revoked key | 401, no private data | Sanitized auth receipt |
| Wrong scope | 403, no resource disclosure | Scope response and identity context |
| Unknown/nonpublic resource | 404, no private existence oracle | Comparison of synthetic responses |
| Invalid input | 422 and no accepted write | Validation and revision evidence |
| Rate limit | 429 with bounded Retry-After |
Controlled plan fixture |
| STAC | Raw standards-based shape unchanged | Media type and parser test |
| Gateway version mismatch | Explicit version/skew diagnostic | Gateway and upstream health |
| Evidence/provenance | Same units, rights, defaults and lineage | Scientific fixture and reviewer |
| Breaking candidate | CI blocks or migration is explicitly approved | Machine-readable diff and change decision |
19. Symptoms
Indicators include new 401/403 responses with an unchanged key; 404 for a previously supported operation; 422 when an optional input becomes mandatory; a missing response field; an unexpected JSON wrapper; an old SDK throwing a method error; a new 429 retry rule; a gateway version mismatch; or a scientific result whose unit, time window or review status changed without a route-version change.
20. Cause
Trace failures to one or more of: changed route or method, public-version mismatch, disabled environment feature, expired or revoked credentials, narrowed scopes, stricter schema, altered default filters, changed media type, SDK URL construction, downstream version skew, migration state, or an unreviewed scientific transform. Distinguish an authorization failure from a genuine object/schema incompatibility.
21. Troubleshooting
- Capture method, path, source and deployed release, SDK version, HTTP status, media type and sanitized
X-Request-ID; do not include tokens or private response data. - Compare public route, response API-version header and
meta.api_version, allowing for documented early-middleware error exceptions. - Confirm required scopes, active application and plan before changing project or source data.
- Run the contract diff against the accepted baseline; review required fields, type changes, filters, pagination and error codes.
- Reproduce the same request outside the SDK to separate SDK path or parsing defects from server behavior.
- Check gateway service version and health independently, including timeouts and circuit state.
- Compare synthetic scientific outputs with unchanged source IDs, units, rights and provenance.
22. Resolution
Correct the client or server only after identifying the failing boundary. Restore the accepted server/SDK pair when necessary, add an explicitly versioned compatibility adapter, correct schema migration, or support parallel major routes. Re-authenticate through an authorized path when scopes are wrong; do not expand privileges just to eliminate an error. Do not retry a failed write until its idempotency semantics are established. Retain the old accepted artifact, trace identifiers, backups and audit records.
23. Verification
Accept a release only when the actual deployed OpenAPI matches the approved route inventory, the old client still passes supported operations, the candidate client passes positive and negative tests, the expected 401/403/404/422/429/5xx cases remain detectable, SDK path composition is correct, gateway version skew is handled, and scientific semantics have independent sign-off. No synthetic or static test can substitute for authenticated staging evidence.
Release receipt fields: source_sha, deployed_release, api_major, manifest_sha256, candidate_sha256, openapi_sha256, sdk_versions, staging_test_results, error_contract_results, authorization_checks, scientific_semantics_review, migration_state, backup_restore_evidence and approver. Mark unexecuted checks pending, never passed.
24. Troubleshooting notes for test owners
The supplied Python offline checker compares deliberately small human-maintained contract manifests, not an arbitrary OpenAPI document. It reports breaking changes for removed operations, changed methods/paths/media, new required inputs/scopes, removed required outputs, changed types, removed success statuses and changed semantic guards. Newly observed error statuses require human review. Its fixture tests also compare request IDs and version headers. It is not an automated proof of tenant isolation, full JSON Schema compatibility, publication rights, model correctness or scientific reproducibility.
When the public API is explicitly disabled or production request-log-salt configuration is missing, the inspected middleware may exit before setting its usual X-SC-API-Version header. Record this as an exceptional failure contract rather than assuming a breaking version migration; a release owner should decide whether to make the error headers uniform.
25. Technical references
- Public API documentation — public major version, error status expectations, response envelope and STAC exceptions.
- Public API middleware — authorization, API-version headers, request IDs and rate-limit handling.
- Public API router and response models.
- Gateway response construction and gateway runtime.
- Python SDK and JavaScript SDK.
- Public API source tests and gateway source tests.
- Production certification, migration and recovery limits.
Last source review: November 20, 2026. Deployment/production verification: pending. Independent scientific review: pending.
