Skip to main content

ai-agent-gateway-cli

Python client for the ai-agent-gateway HTTP/SSE protocol, shipped as the hank entrypoint.

Usage

python -m agent_gateway_cli login
python -m agent_gateway_cli chat "hello"
python -m agent_gateway_cli --config-namespace cashnerd login
python -m agent_gateway_cli --config-namespace cashnerd chat --session default "hello"
hank login
hank chat
hank chat "hello"
hank chat --model-key anthropic.claude-sonnet-5 --effort high \
  --model-key-for plan.author=anthropic.claude-opus-5-5 \
  --effort-for plan.author=high "research this company"
hank chat --model-key anthropic.claude-opus-5-5 --save-preference "remember this choice"
hank chat --show-thinking "walk me through the margin bridge"
hank control health

The default config namespace is agent-gateway for python -m agent_gateway_cli and hank for the hank entrypoint, which writes:

  • ~/.cache/hank/cli_config.json
  • ~/.cache/hank/sessions/<name>.json

--config-namespace cashnerd writes under ~/.cache/cashnerd/ instead. The namespace directory and its sessions/ directory are created mode 0700; the files inside are 0600.

Each named session file holds a local transcript only. Conversation continuity is held by the gateway session for about an hour and does not survive a gateway restart; when it lapses, the CLI prints a notice and starts a new conversation.

hank chat with no message on an interactive terminal replaces the process with the agent-gateway-tui binary (the Node >= 24 package @henrychien/agent-gateway-tui), passing the resolved namespace and session as arguments and the resolved connection as GATEWAY_BASE_URL, GATEWAY_API_KEY, GATEWAY_USER_ID, and AGENT_GATEWAY_ROUTE_PREFIX. hank chat "<message>" and any non-interactive stdout run the Python client in this package instead.

The Python client prints streamed thinking only with --show-thinking: the model's summarized thinking appears dimmed on a [thinking] line ahead of the [text] reply. Without the flag, thinking deltas go to the debug log only. The TUI shows thinking by default and needs no flag.

When the provider refuses a turn (a refusal event), the Python client keeps the text already delivered, prints [refusal] <category>: <explanation> and [refusal] <guidance> after it, and exits 0; nothing is reset, and the guidance is to start a fresh conversation before continuing.

Contract

The CLI sends context.channel = "cli" on every chat request. When user_id is configured, it is sent as a top-level field on both /api/chat/init and /api/chat. Tool approvals post tool_call_id, nonce, approved, and allow_tool_type.

The CLI consumes authenticated capability_choices from /api/chat/init. --model-key accepts only an exact session-eligible stable key, and --effort requires it. When both are omitted, the chat request omits all selection fields and the server resolves the capability default. Repeatable --model-key-for CAPABILITY=MODEL_KEY and optional --effort-for CAPABILITY=LEVEL flags populate strict init-time run overrides. Provider-qualified selectors, upstream model names, display-label aliases, and local fallback catalogs are not accepted.

--save-preference and --clear-preference use the authenticated server preference contract for account-wide session.driver state. Local transcript files do not store or resolve model preferences.

Every gateway request is composed as base_url + route_prefix + path, so the hosted deployment is reached as https://hank.investments/gateway/api/chat/init. The default BaseUrlPolicy accepts any hostname over https, allows http only for a loopback host, and rejects a query or fragment. A base URL may carry the deployment path: it is hoisted out of the base URL into the route prefix, so --base-url https://hank.investments/gateway resolves to base URL https://hank.investments with route prefix /gateway/api, identical to --base-url https://hank.investments --route-prefix /gateway/api. An explicit --route-prefix (or AGENT_GATEWAY_ROUTE_PREFIX) that neither equals nor extends the base URL path is refused, naming both values. TLS verification is on by default; --insecure and HANK_INSECURE=1 are honored only for a loopback gateway, and HANK_CA_BUNDLE selects a custom CA bundle. Products that need a narrower policy can inject BaseUrlPolicy(allowed_schemes=..., allowed_hostnames=...).

Control plane

Chat and control use separate credentials and separate channels. hank login --control-api-key <key> [--control-channel <channel>] stores the control key in the same namespace config file. Chat requests always send context.channel = "cli"; control sessions default to --control-channel tui (cron/scripts convention sets AGENT_CONTROL_CHANNEL=cli instead). Whichever channel is used MUST match the channel of the GATEWAY_USER_KEYS entry the control key belongs to, or session mint fails with ChannelMismatch.

hank control <subcommand> drives /api/control/*: dispatch starts an autonomous run (--profile analyst --mode once|skill … [--follow]); runs, run, logs, watch, cancel observe and steer it; approvals/approve/ deny, batches, artifacts, and schedules cover the rest. Run listings are owner-and-channel scoped: hank control runs shows only runs started on the control key's channel (documented in docs/reference/agent-run-evaluation.md).

Approvals are server-side standing policy, not a per-run CLI flag: the product default auto_approve_all_but_trades prompts only for live trade execution, and hank control approvals --policy request_user_approval is the opt-out that restores prompts for every tool class (--show-policy reads the current one, bare hank control approvals still lists pending approvals).

Metadata

Release files for ai-agent-gateway-cli 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-agent-gateway-cli 0.8.1
File Size Uploaded
ai_agent_gateway_cli-0.8.1.tar.gz 131.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-agent-gateway-cli 0.8.1
File Interpreter ABI Platform
ai_agent_gateway_cli-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 206.6 kB

Release files / ai_agent_gateway_cli-0.8.1.tar.gz

Download URL ai_agent_gateway_cli-0.8.1.tar.gz
Size 131.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ebfe89b6e81713c472bcaadb77808a7fe1c59c87cccb8eb6eb65a478fe744854
BLAKE2b-256 checksum
How to use checksums
79a02552da07033c4bb138c07f2000c8b1716fd186ebf273248350b752c661cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / ai_agent_gateway_cli-0.8.1-py3-none-any.whl

Download URL ai_agent_gateway_cli-0.8.1-py3-none-any.whl
Size 75.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81e1d35e90b1b593cedbcb3c6994e1e3c73473acbf3f86d201e9bd9791d85c41
BLAKE2b-256 checksum
How to use checksums
ad51ac6070073b5e8409c64413448e2196325ed0684a0ef0cc970260ef32fc14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page