> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jojapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Command-line interface

> Manage your APIs from a terminal, CI or an AI agent: Worker code and deployments, bindings and variables, endpoints and their OpenAPI document, pricing, traffic and request logs.

The `jojapi` CLI works with your APIs from a terminal, a CI job or an AI agent. It uses the [Management API](/studio/management-api) with a scoped token. Every write that cannot be undone shows what will change and asks before it runs.

```bash theme={null}
npm install -g @jojapi/cli          # or: npx @jojapi/cli …
jojapi login --token jm_…           # Studio → Management API
jojapi help                         # every command; jojapi <command> --help for its arguments
```

Inside a project made by `jojapi pull`, commands use the API named in `jojapi.json` unless you pass a slug.

## Token scopes

Give the token the scopes your commands use. A command whose scope is missing stops and names the scope it needs.

| Scope | Commands |
| - | - |
| `code:read`, `code:write` | `pull`, `dev`, `deploy`, `logs`, `errors`, `status`, `deployments`, `changes`, `promote`, `rollback`, `resources`, `vars`, `settings`, `usage`, `mode` |
| `listings:read`, `listings:write` | `info`, `create`, `update`, `resubmit`, `endpoints`, `groups`, `faqs`, `objects`, `features`, `page`, `export`, `import` |
| `plans:write` | `plans`, `billing`, `agents`, `grant` |
| `analytics:read` | `dashboard`, `traffic`, `requests`, `transactions`, the traffic columns of `apis` |
| `subscriptions:read` | `subscribers`, `grant` |

## Code and deployments

```bash theme={null}
jojapi pull my-api && cd my-api     # the Worker's files, .dev.vars.example, wrangler.jsonc
jojapi dev                          # wrangler dev with the gateway's x-jojapi-* headers added
jojapi deploy                       # a preview deployment on its own URL; --prod for production
jojapi changes                      # saved changes production does not run yet
jojapi changes deploy --note "…"    # promote the preview that holds them (public release note)
jojapi rollback                     # back to what production served before
```

Every save is a [preview first](/studio/deployments#every-save-is-a-preview-first). This covers code, variables, bindings and the mode. `--prod` on `deploy`, `resources`, `vars` or `mode` puts only that change into production at once, for example to rotate a leaked key. `jojapi deployments keep|public|archive <id>` changes one deployment, and `jojapi changes discard` returns the working copy to what production runs. To deploy from GitHub, see [Deploy from GitHub](/studio/github-actions).

## Bindings, variables and settings

```bash theme={null}
jojapi resources add kv CACHE                 # also d1, r2, queue, or do --class Counter
jojapi resources share CACHE other-api --as CACHE
jojapi vars set REGION=eu
printf %s "$UPSTREAM_TOKEN" | jojapi vars set UPSTREAM_TOKEN --secret
jojapi settings --logs on
jojapi usage --days 30
```

The CLI never takes a secret as an argument, because the value would stay in the shell history. Type it at a prompt that does not echo it, or pipe it in. `resources remove` and `vars unset` ask before they run. Removed storage and its data are deleted once no active deployment uses it, so a rollback still finds it. See [Shared resources](/studio/shared-resources) for grants between APIs.

## Endpoints as code

`jojapi export` writes the API as an OpenAPI 3.2 document, hidden endpoints included. Importing that document again changes nothing, so you can keep it in a repository and edit it there:

```bash theme={null}
jojapi export --output openapi.yaml
# edit openapi.yaml
jojapi import openapi.yaml
jojapi import openapi.yaml --apply --expect 4005bae33aac
```

`jojapi import` changes nothing until you add `--apply`. First it prints every change, field by field:

* new endpoints, with their parameters, body and responses;
* for changed endpoints, each value before and after, with JSON paths inside schemas and examples;
* endpoints missing from the document;
* the API's details.

It ends with a **digest** of exactly that preview. `--apply --expect <digest>` applies that preview and nothing else. If the document, the options or the API changed since the preview, it refuses. Without a terminal, which covers CI and agents, `--apply` requires `--expect`. In a terminal, `--apply` without `--expect` shows the preview and asks first.

What an import changes, and what it leaves alone:

| | Default | Option |
| - | - | - |
| Changed endpoints | overwritten with the document | `--keep-changed` keeps them |
| Endpoints missing from the document | kept | `--hide-missing` hides them from the docs (never deleted) |
| New endpoints | created in the docs, requests on, not billed | `--new-hidden` creates them hidden |
| The API's name, description, about text | unchanged | `--metadata name,description,about` |
| Billing, requests on/off, groups and order of existing endpoints | never changed | — |

The CLI reads OpenAPI (JSON or YAML) and Postman Collections, from a file or a URL. `jojapi import` without a source re-imports from the URL of the last import. RapidAPI and Apify imports run in the Studio.

For quick edits there are smaller commands. `jojapi endpoints show|add|update|hide|disable|delete|duplicate|move` changes one endpoint, and `jojapi endpoints example` stores a response example. `jojapi groups`, `jojapi faqs` and `jojapi objects` manage the rest of the listing. `jojapi update --marketplace public` submits the API for review, and if it is refused it names the checks that failed. `jojapi page` shows the marketplace page as consumers see it.

## Pricing

```bash theme={null}
jojapi plans create --price 9.99 --quota requests=10000 --name Pro
jojapi plans public <plan>
jojapi billing requests --cost 1 --all
jojapi agents price 0.05 --all
jojapi grant alice requests 5000 --note "Sorry for the outage"
```

New plans are private until you make them public. Price, currency, period and included quotas never change; for a new price, create a new plan and [transfer subscribers](/studio/managing-subscriptions) to it in the Studio. Each pricing command shows what will change before it asks. That includes plans that would refuse an endpoint (402), the subscribers `plans add-object` will email, and the fact that a `grant` adds again if you run it twice. See [Billable objects](/studio/billable-objects) and [Agent payments](/studio/agent-payments).

## Traffic and logs

```bash theme={null}
jojapi apis                         # your APIs with 7-day traffic
jojapi traffic --period hour        # requests, status classes, latency, billable units
jojapi requests --status 502 --details
jojapi subscribers
```

Request logs never show credentials or cookies, not even in `--json`; a `jk_` key is shortened to its last four characters. Request bodies are never logged. `--details` adds the consumer's IP address, the headers and the response body.

## Scripts and agents

* Read commands, `deploy`, `import`, `resources`, `vars` and `mode` take `--json` and print one line of JSON. Progress goes to stderr.
* A command that asks first won't run without a terminal; it prints what would change instead. `--yes` answers the question. `import --apply` takes `--expect <digest>` instead of `--yes`.
* Exit code `0` means done, or nothing to do. Any other code means a refusal, a failure or a usage error, with the reason on stderr.
* `JOJAPI_TOKEN` and `JOJAPI_BASE` override the stored configuration, so CI needs only `JOJAPI_TOKEN`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.