Skip to Content
CLI

APIGit CLI

apigit is the command line for APIGit. It checks OpenAPI files on your machine or in CI, and it publishes API documents and mock servers from the repositories you keep on APIGit.

The CLI is what makes APIGit local-first: from a clone of your repository, you or a coding agent such as Claude Code or Codex can check, preview and mock an API on your machine, and publish the result when it is ready. See Use it with an AI agent.

npm install -g @apigit/cli apigit lint openapi.yaml

You can also run any command without installing: npx @apigit/cli lint openapi.yaml. Node.js 20 or later is needed. The CLI is free to use (MIT license) and sends no telemetry.

Check a file, no account needed

These commands work offline. apigit preview downloads the viewer of the published pages the first time it runs.

CommandWhat it does
apigit lint openapi.yamlLints the file with the same rule sets as the APIGit editor.
apigit score openapi.yamlScores how ready the API description is for AI agents, from 0 to 100, with a line per rule.
apigit bundle openapi.yaml -o dist/openapi.yamlWrites one file with every external $ref resolved.
apigit diff main HEAD openapi.yamlLists what changed between two commits, branches or tags (or two files), with the changes that can break a client first.
apigit breaking main HEAD openapi.yamlLists only the breaking changes and exits 1 when there is one.
apigit previewServes the whole repository on your machine as the published page will show it. See Preview the site on your machine.

Rule sets

lint uses, in this order: the file given with --ruleset, the built-in set given with --builtin, a .spectral.yaml in the working directory, then the built-in oas-best-practice.

Built-inChecks
oas-best-practiceOpenAPI and AsyncAPI best practice (the editor’s default)
owasp-top10OWASP API Security Top 10
url-guidelineURL versioning style
documentDocumentation quality

A rule set file is a Spectral  rule set, the format you edit under API Governance in APIGit.

AsyncAPI lint and GraphQL validation

CLI 0.6.0 includes AsyncAPI lint and GraphQL SDL validation. Upgrade an older installation with npm install -g @apigit/cli@latest; the CI examples below pin 0.9.0. mock serve for a GraphQL schema needs 0.7.0 or later, and the saved site settings in preview need 0.8.0.

apigit lint events.yaml # AsyncAPI 2.x or 3.x, default best-practice rules apigit lint schema.graphql # SDL syntax and schema checks apigit lint schema.graphql --fail-severity warn

The default oas-best-practice set applies the rules for the file’s format, OpenAPI or AsyncAPI. Its name stays the same. The owasp-top10, url-guideline and document builtins remain OpenAPI-only; selecting one for an AsyncAPI document produces an error.

GraphQL files ending in .graphql or .gql are checked directly rather than against Spectral rules. Broken syntax is a graphql-syntax error. Unknown types, duplicate names and other schema problems are graphql-schema warnings, because a file may be part of a larger schema. The default failure threshold is error; --fail-severity warn makes those warnings fail CI too.

score, bundle, diff and breaking remain OpenAPI-only. Browser AsyncAPI governance is live; server-side lint and account MCP lint_spec are not enabled on the hosted service. They require a configured lint service and do not validate GraphQL schemas. See the format support table.

Sign in

apigit auth login apigit auth status

apigit auth login prints a short code and opens a page in your browser. Check that the page shows the same code and click Authorize: the CLI is then signed in. The token it received is listed under Settings › Personal Access Token, where you can delete it (Personal access tokens).

On a machine without a browser, create a token under Settings › Personal Access Token, choose CLI and automation, and pipe it in:

echo "$TOKEN" | apigit auth login --with-token

The login is kept in your system keyring when there is one (the macOS Keychain, or the Secret Service on Linux through secret-tool), and otherwise in ~/.config/apigit/hosts.yml, a file only you can read. apigit auth status shows which. apigit auth login --insecure-storage keeps it in the file.

A “Git and repository API” token also works for documents and mock servers. The “CLI and automation” kind adds what apigit plan and organization rules read.

Regions

APIGit Cloud runs in two regions, each with its own accounts and tokens. The CLI talks to the United States region unless you name the other one (CLI 0.9.0+):

apigit login --region eu # sign in to the Europe (EU) region and make it the default apigit auth status # prints a Region: line apigit --region us doc list # one command against the other region
RegionHostWhere the data is stored
us (default)https://app.apigit.comUnited States
euhttps://app.eu.apigit.comStockholm, Sweden

Every command takes --region us|eu. Without it the CLI uses, in this order, APIGIT_REGION, region: in apigit.yaml, the default of the stored login, and then us. In CI, set APIGIT_REGION=eu next to APIGIT_TOKEN: a token belongs to one region and is refused by the other.

Publish documents and mock servers

Commit and push with git first: a publish uses a commit that is already on APIGit. Inside a clone the CLI finds the repository from the origin remote; elsewhere pass -R <owner>/<name>.

apigit doc publish --version 1.2.0 --access public # the pushed HEAD apigit doc list apigit doc unpublish 1.2.0 apigit mock publish --name petstore --type spec --mount openapi.yaml apigit mock call petstore /pets apigit mock logs petstore apigit mock delete petstore
  • --commit <sha> publishes a specific commit; --ref <branch> follows a branch, on plans that include it.
  • --dry-run prints what would be sent and sends nothing.
  • doc unpublish and mock delete ask for confirmation in a terminal and need --yes in a script.
  • apigit plan shows your plan, its limits and this month’s mock usage.

Publish a hosted GraphQL mock with apigit mock publish --name catalog-sandbox --type spec --mount schema.graphql:/graphql. This uses the deployed backend and works with the existing publish command. See GraphQL mock servers.

Preview the site on your machine

apigit preview shows the repository you are working in as the published document will look, before you commit or publish anything. It needs no login; with one, it also shows the repository’s saved look (below):

apigit preview # the whole site of this repository apigit preview docs/intro.md # the same, opened on that page apigit preview --no-tryit # as a version published without Try it

The page opens in your browser at http://127.0.0.1:4011 (--port changes it, --no-open leaves the browser alone) and reloads when you save a file.

  • The same viewer. The page is drawn by the viewer of the published pages, not by a copy of it: Markdown and MDX with the built-in components, OpenAPI (including Swagger 2.0 files), AsyncAPI and GraphQL SDL render as they do once published. The file tree, navigation and OpenAPI Try It Out use that viewer too. The viewer is downloaded separately from the CLI; it uses Redoc 3 and has no Swagger UI switch.
  • Your working copy. The site is what a commit of the current state would contain: the files git tracks plus the new ones it does not ignore, with your uncommitted edits. Files that .gitignore excludes are never shown.
  • Navigation and theme. An apigit.json in the repository is applied as it is on the published page: its navigation, its icons and its theme.
  • The saved site settings (CLI 0.8.0+). When you are logged in (apigit auth login, or APIGIT_TOKEN) and the folder belongs to a repository on APIGit, the preview reads the site settings saved for that repository in the Publish Center, once, when it starts: the theme, colours, appearance, fonts, document name, logo, favicon, header links, footer and banner. The repository is the one -R <owner>/<name> names, else repo in apigit.yaml, else the origin remote of the clone. One line at start says what happened: Site settings: from <owner>/<name>, or Site settings: none (<reason>); showing the default look.
  • Works offline. The first run downloads the viewer (about 9 MB) and keeps it on your machine. Later runs start from that copy, also without a connection, and fetch a new one only after the viewer has been updated.

What differs from a published version:

  • There is one version, named local.
  • The saved site settings are not read when you are not logged in, when no repository is found, when the repository does not exist or your login cannot read it, or when APIGit does not answer within 5 seconds. The preview then starts with the default look and says why. --no-site-settings switches the request off.
  • --theme sequoia|clover|fern|cedar|juniper|birch|alder, --primary-color <hex> and --text-color <hex> set the look by hand and win over the saved values; a theme in apigit.json wins over both.
  • The site’s Google Analytics id is never used: the local page loads no analytics.
  • The addresses AI agents read (llms.txt, the Skill, the MCP server) exist only for published versions. Copy page works locally.
  • There is no sign-in, sharing or access control: the page is served to your machine only.

Nothing about your files leaves your machine unless you send it. Reading the saved settings is one request for that repository’s settings, and an image uploaded in them (a logo, a favicon) is fetched from APIGit when the page shows it. Try it sends a request the browser cannot send itself through APIGit’s proxy, as on the published page (the proxy cannot reach a server on your machine, such as a local mock), and Open in ChatGPT or Open in Claude in the Copy page menu pass the page’s text to that site. The page loads no analytics.

The API checks (lint, score, bundle, diff and breaking) and spec-based mocks currently support OpenAPI. AsyncAPI and GraphQL viewing in preview is already available. CLI 0.6.0 also supports AsyncAPI and GraphQL in lint; the other checks keep their existing format scope. Since CLI 0.7.0, mock serve also runs a GraphQL schema. See Supported API Formats.

Run a mock on your machine

apigit mock serve runs a mock locally that answers as the published one will, before you commit or publish anything. It works offline and needs no login:

apigit mock serve openapi.yaml # a spec-based mock of an OpenAPI file apigit mock serve schema.graphql # a GraphQL mock of a schema, at /graphql (CLI 0.7.0+) apigit mock serve apigit-mock # a code-based mock: the folder with main.js

The mock listens on http://127.0.0.1:4010 (--port changes it) and follows your edits without a restart.

  • Spec-based. The same engine as the hosted mock servers: routing, request validation, examples, generated responses and the Prefer header behave the same.
  • Code-based. main.js runs against the same Express app as on APIGit: the global mock, the global state and the pre-installed libraries at the same versions. A library outside that list fails here as it would there.

On your machine state starts empty and lasts until you stop the command, there is no access token, quota or request log, and the script is not sandboxed: it runs with your rights, like any Node.js script.

Without a target the command serves the one file under specs in apigit.yaml, or else the apigit-mock folder; --type spec or --type code chooses when both are there.

A GraphQL schema (.graphql, .gql) is served at /graphql: POST {"query": "..."} or GET with ?query=. The answers have the shape of the schema with generated values, as on the hosted mock; subscriptions are not mocked. This needs CLI 0.7.0 or later.

Use it in CI

Set APIGIT_TOKEN as a secret; the CLI reads it and stores nothing.

# GitHub Actions - uses: actions/setup-node@v4 with: node-version: 22 - run: npx @apigit/cli@0.9.0 lint openapi.yaml --format github-actions - run: npx @apigit/cli@0.9.0 doc publish --version ${{ github.ref_name }} --commit ${{ github.sha }} --access public env: APIGIT_TOKEN: ${{ secrets.APIGIT_TOKEN }}

GitHub Actions without a stored secret

A repository admin says once which GitHub repository’s workflows may act on the APIGit repository:

apigit ci trust add my-github-org/petstore --ref refs/heads/main -R my-org/petstore

A job of that repository then signs in with the identity token GitHub issues to it:

permissions: id-token: write contents: read steps: - uses: actions/checkout@v4 - run: npx @apigit/cli@0.9.0 auth login --github-oidc -R my-org/petstore - run: npx @apigit/cli@0.9.0 doc publish --version v1 -R my-org/petstore

The login lasts one hour and works on that one repository: its files, branches, pull requests, documents and mock servers, not its settings, collaborators or share links. The first sign-in pins the trust to that GitHub repository’s id, so the same name registered again by someone else is refused. apigit ci trust list and apigit ci trust remove <id> show and end a trust. Without --ref, every branch and pull request of the GitHub repository can sign in.

On any other CI system run npx @apigit/cli … with the same arguments. lint also writes junit, sarif and json.

For pull requests:

apigit breaking origin/main HEAD openapi.yaml # fail on a change that can break a client apigit lint --org my-org --report-status # add your organization's rule sets; post the commit status apigit/lint

--org adds the governance rule sets of your organization that apply to the repository. --report-status posts the result on the commit, and a branch protection rule can require it before a merge.

Exit codes

CodeMeaning
0Success
1The check failed: findings at or above --fail-severity, or a score below --min
2Wrong arguments, or the command could not run
3Not signed in, or not allowed
4Not found
5Conflict
6Plan limit reached
7Network or server trouble; safe to retry

Upgrade

apigit upgrade # install the latest version apigit upgrade --check # only report the installed and the latest version

apigit upgrade runs the package manager that installed the CLI. For a project dependency or an npx run it prints the command to run instead. On a terminal the CLI checks once a day for a newer version and prints one line when there is one; it stays silent in CI, in a pipe and with --json, and APIGIT_NO_UPDATE_CHECK=1 turns the check off. The CLI never updates itself.

To make a repository state the version it expects, add cliVersion: ">=0.1.0" (or an exact version) to apigit.yaml. In CI, pin the version: npx @apigit/cli@0.9.0 ….

Use it with an AI agent

apigit skills install

This copies an Agent Skill  that teaches coding agents the CLI into .agents/skills/ (and .claude/skills/ when that directory exists). It prints each path and writes nothing else. --json on any command prints one JSON value, and apigit context lists every command and option as JSON.

Connect an agent with MCP

apigit agent setup # Claude Code; or --client cursor, --client vscode

This adds an APIGit server to the agent’s configuration in your project. The agent starts apigit mcp, which uses your apigit auth login, so no token is written to a file. The server gives the agent:

  • tools on the OpenAPI files in your working directory that need no network: lint, bundle, outline, one operation
  • read-only tools on your APIGit account: repositories, OpenAPI files at any branch, tag or commit, the changes between two of them, pull requests, published documents, mock servers and their request logs, and your organization’s rule sets

Set up this way, nothing can change a repository, a document or a mock. apigit agent setup --write adds the tools that do: create a branch, commit or patch files on a branch, open a pull request, publish or remove a document version or a mock. They never write to the default branch or a protected branch, never make a document public and never turn a mock’s access control off; a person merges and does those in the application.

An agent host that connects to a URL, such as a chat application, uses the APIGit MCP server directly: that page lists every tool, how each kind of host signs in and how to disconnect one.

To let an agent read a published API document (its llms.txt, Markdown pages and MCP server), see Use a published API document with AI agents. apigit doc view <version> prints those addresses.

Last updated on