# MyOpenGov agent guide

Discover the contract without a key at [OpenAPI](https://myopengov.au/api/openapi.json), [Swagger](https://myopengov.au/api/docs), [llms.txt](https://myopengov.au/llms.txt) or the [API catalog](https://myopengov.au/.well-known/api-catalog). The REST base is **https://myopengov.au/api/v1**. Only the operations in OpenAPI are supported. There is **no published MCP endpoint or transport**. `/mcp`, `/openapi.json` and `/api/v1/releases` are not this API's contract.

## Secure setup

The user signs in at [Manage API keys](https://myopengov.au/account/api-keys) and creates an account-bound key. Read it from a secret store or a private local prompt. Do not request a key in chat, put it in a query string, log it, commit it or use `X-API-Key`. Send `Authorization: Bearer <key>` only to `https://myopengov.au/api/v1/...`. Browser cookies alone do not authorize requests. Public docs need no key; preview does not accept production keys. Cross-origin browser API calls are not enabled.

This Python example prompts locally without echoing the key and disables automatic redirects. It prints response data, never the request header. Do not run it in a shared session that records secret input.

```python
import getpass, json, urllib.request, urllib.error

class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None

key = getpass.getpass("MyOpenGov API key: ")
request = urllib.request.Request(
    "https://myopengov.au/api/v1/search?q=employee&type=defined_term&limit=10",
    headers={"Authorization": "Bearer " + key, "Accept": "application/json"},
)
try:
    response = urllib.request.build_opener(NoRedirect).open(request, timeout=20)
except urllib.error.HTTPError as error:
    response = error  # Inspect 300/301/302 and errors instead of hiding them.
if not response.headers.get("Content-Type", "").startswith("application/json"):
    raise RuntimeError(f"Non-API response: HTTP {response.status}; CF-RAY {response.headers.get('CF-RAY')}")
print(response.status, json.loads(response.read()))
```

## Search employee, then resolve the intended meaning

1. `GET /search?q=employee&type=defined_term&limit=10` returns candidates, not a universal definition. Compare `work`, `provision`, `label` and `definition_count`, then inspect the chosen term’s `scope`. Fetch `GET /works/{work-id}` for the Act/instrument title and coverage. Search `type=work` when the user names an Act. Ask for the intended work, scope and date when they remain ambiguous; never pick the first matching label by default.
2. Follow the chosen candidate's `api_url` to the defined term. Its `definitions` are references. A term has no single definition text of its own. Preserve the returned term slug, case and scope suffix; do not construct it from the label. The API IRI resolver accepts canonical MyOpenGov IRIs, including encoded fragments, and does not fetch arbitrary URLs.
3. Read the term's history using its `links.history`. For a requested date call its API path plus `/at/YYYY-MM-DD`; `/latest` uses today's calendar date in Canberra. Keep redirect handling manual. A **302** identifies one recorded definition in `data.definitions` and `Location`, with its date-specific details in `data.definition_data`; a **300** returns multiple concurrent definitions and their `data.definitions_data`, with no preferred choice. Retain these response bodies: following the canonical `Location` defaults attracted meanings to today and loses the requested date context. Follow only a verified URL under the canonical HTTPS API base and bound redirect hops (for example, five). A **301** is a recorded address move; a **410** is a recorded retirement.
4. Inspect the selected definition's `text`, `scope`, `history`, `text_versions`, `evidence`, `sources`, `parts` and attracted meanings. Use the temporal response's definition details for a dated question; fetch its canonical `api_url` only when today's selection is appropriate. An `/at/` result selects an enacted definition, not a pre-rendered text snapshot: partial amendments can have separate `text_versions` within that definition. Inspect their date windows and evidence. Do not equate top-level text with wording at the requested date when versions or dates are unresolved. Attracted-meaning candidates, conditions and review states remain qualifications, not established equivalences.
   A definition recorded as in force today carries `currency` (a term lists them in `in_force_today`). Its words are the definition's own, as made; they are today's words only when `currency.code` is `matches_latest_compilation` (the latest compilation held is in force with the same words). Otherwise later amendments may not be shown: check `currency.register_latest`. `currency.register_checked_to` is the date the Register data is checked to, not a build date.
   On contract 2.0.0 data a work is the law itself (`/works/{id}`: its `defined_terms` scheme, its `in_force_today` versions and `latest_version_confirmed`); `/works/{id}/versions` lists every version the Federal Register lists, `/works/{id}/at/YYYY-MM-DD` and `/latest` answer the version in force (302, or 300 for versions taking effect the same day), and `/works/{id}/provisions` and `/resolve?iri=` give a provision's definitions and the signposts citing it. Version and provision texts are not held: follow each version's `links.register`.
5. Cite the published definition `iri`, work title/ID, the provision in `evidence`, the relevant instrument/version, requested date and observed `data_version`. Link the returned official Federal Register source in `sources`, and retain commencement/ending evidence and uncertainty. Check the linked official source before presenting wording as authoritative. A work-level Register link alone does not verify an exact provision or historical wording.

If definition resolution returns 404, read `error.code`: `not_yet_defined`, `dates_unsettled`, `definition_ended`, `work_ended`, `work_end_unrecorded` and `no_definitions` differ from `not_found`. Preserve `possible_definitions`, date bases, endings and `last_recorded`; do not turn uncertainty into a definitive answer.

## Pagination, input limits and errors

- Lists use `page` (1–1000000) and `limit` (default 50, maximum 100). Follow the complete `pagination.next` URL until null, retaining its `data-version`. An empty page past the end is not proof that the entire collection is empty. If your own retrieval budget ends early, report how many candidates you inspected and that more remain.
- Full-text work and defined-term search accepts up to 200 characters and eight Unicode letter/number tokens. Excess tokens return 400, never silently truncate. Recover by splitting the research into shorter focused queries, preserving the user's constraints when comparing results; do not simply discard the remaining words. Earlier tokens are exact and the final token is a prefix; this is lexical discovery, not semantic search. Shared meanings use literal label prefixes; work-local term filtering uses a literal substring. Unknown/repeated parameters and invalid calendar dates return 400.
- `data_version` identifies the current published build. It is not a valid-on date, registration date or source-document date. Pagination detects a changed build with **409 `data_version_changed`**. Restart the search instead of mixing pages. Compare `data_version` on subsequent detail/temporal calls too; individual resources do not accept a historical release selector.
- API errors are JSON with `error.code` and `error.message`; authorization errors may lack `data_version`. **401** means missing/invalid/expired/revoked credentials. **403** JSON can mean a disallowed API origin. **429** has `Retry-After` in seconds; wait at least that long, use bounded backoff and do not rotate keys to evade the account limit. Current limits are 60 requests/account/minute and an approximate 120 requests/IP/minute edge limit. Keys expire after 90 days.
- **503** means data/authentication service unavailable, unsupported data format, or a resource limit. Do not interpret it as no matching legislation. RDF limits return `resource_limit` instead of incomplete triples; a smaller exact IRI may be appropriate. Other transient 503s may be retried a small, bounded number of times with backoff. There is no guaranteed Retry-After header on 503.
- All API responses are private, no-store. Collection pages are bounded; a single term, temporal result or definition can still contain many references or versions. OpenAPI does not promise a universal JSON byte cap or an extraction-completeness flag. Preserve all returned items/qualifications or explicitly disclose client-side truncation.

## Coverage, dates and citations

The API reads a published extraction, not a live Federal Register query or a legal opinion. Work metadata exposes `catalogue_status` and `has_scheme`; catalogue presence does not prove extracted definitions exist. Missing sources, absent versions or empty results do not establish that legislation has no relevant definition. Source assertions and recorded versions are evidence inventories, not a verified completeness guarantee. Source-file/fragment hashes are not provided by this API.

Keep `made_on`, `registered_at`, recorded commencement, exclusive endings, requested valid-on date and publication `data_version` separate. The [manifest](https://myopengov.au/data/manifest.json) supplies build provenance and requires a signed-in browser session. API clients should retain the returned `data_version`; it is not an applicability date. This service does not offer immutable historical API releases. Retain the observed version and official source evidence when recording a result.

Legislative text is from the Federal Register of Legislation under CC BY 4.0; derived MyOpenGov artefacts are CC BY-NC 4.0. See [licensing](https://myopengov.au/data#licensing) and preserve attribution and the relevant source links.

## Discovery fails before the API

A plain-text Cloudflare 403 with `error code: 1010` is an edge denial. It does not prove a route is missing or a key invalid. Capture the requested URL, timestamp, Content-Type and CF-RAY for the site owner. Do not send more credentials, spoof headers or switch to an unapproved host. Public discovery must be reachable by intended machine clients before authenticated API verification is useful.

## Changes

- **1.2.0 (2026-10-24).** Nothing is in force once a law has ended. A law's end is its Register-dated end, or a repeal or cessation the Register scheduled whose date has passed, or the Register's own status entry. For such a law `in_force_today` is empty and `/works/{id}/latest` and `/at/{date}` answer 404 `work_ended`, terms included. A version row whose status is Repealed, Ceased or NeverEffective is the Register's record of the repeal or cessation, so it gains `is_status_entry: true` and is never in force: **`/works/{id}/at/{date}` after a law's end now answers 404, where it answered 302 or 300 with such a row.** New fields: `is_status_entry` on versions, and `ends_with_work` on term history entries and text versions (the law's end, where the release gives the definition no end of its own). `/works/{id}` gives every title's `end`, including laws without a scheme and scheduled ends. A definition's `currency.code` is the code the page shows. `/resolve` of a 1.x version address answers 404 where the Register's versions do not list it.
- **1.1.0 (contract 2.0.0 data, 2026).** New: `/works/{id}/versions`, `/works/{id}/latest`, `/works/{id}/at/{date}`, `/works/{id}/provisions`; on `/works/{id}` the fields `defined_terms`, `version_count`, `in_force_today` and `latest_version_confirmed`; through `/resolve`, a work's defined-terms scheme (`defined_terms`), every version (`work_version`) and a provision (`provision`). **Breaking for one path:** `/resolve?iri=https://myopengov.au/{id}/asmade` returns a `work_version`, as every other version does, where it returned a `resource_description` (the work is the law and its as-made version is one of its versions, decision D32). Every other existing response is unchanged or gains fields only.
