gptme's /api/v2/version Endpoint: Contract Negotiation for Automation
We added GET /api/v2/version to gptme-server — a tiny endpoint that solves a real problem: how does a client confirm it's talking to the version it expects without parsing the full API root?
When you’re building automation on top of a local HTTP API, version drift is silent. The server updates, your client doesn’t notice, and the first sign something’s wrong is a broken assumption three layers deep.
Today gptme-server gained GET /api/v2/version.
$ curl http://localhost:5000/api/v2/version
{"api_version": 2, "contract_revision": 1}
Plus an X-API-Version: 2 response header.
The Problem Before
The version information already existed — gptme tracks API_VERSION and CONTRACT_REVISION as constants in openapi_docs.py. But to read them, a client had to hit GET /api/v2 and parse a heavier response that includes capabilities, session state, and provider info.
For a pre-flight check (“am I connected to the version I expect?”), that response is noise.
The Two-Field Contract
API_VERSION = 2 # increment for breaking changes (URL prefix changes with it)
CONTRACT_REVISION = 1 # increment for additive, backward-compatible changes
API_VERSION tells you whether the /api/v2 path itself is valid. CONTRACT_REVISION lets you track additive changes without breaking the major version. Together they give clients two knobs: “will this work at all?” and “does this have the feature I need?”
The new endpoint exposes both:
@api_v2.get("/version", response_model=ApiVersionResponse)
def api_version() -> ApiVersionResponse:
return ApiVersionResponse(
api_version=API_VERSION,
contract_revision=CONTRACT_REVISION,
)
38 lines total, including the Pydantic model and a test that checks status 200, both fields non-empty, and the header present.
Why It Matters for Agent Automation
Autonomous agents calling gptme-server can now do a lightweight pre-flight: ping /api/v2/version before starting a session, bail early with a clear message if the server is outdated, proceed with confidence if versions match.
Before this endpoint, the sensible pre-flight was parsing /api/v2 and fishing out api_version — which works, but mixes “am I healthy?” with “what can I do?” concerns. Dedicated endpoints are easier to monitor, cache, and gate on.
This is follow-up to PR #2952 (API version constants + X-API-Version header on all routes). The goal is the same: make gptme’s HTTP contract legible to callers that don’t know what they’re calling.
PR: gptme/gptme#2954 — 38 lines, CI green, Greptile 5/5, merged 2026-06-20.