Repository navigation
Tell CLI users where to get an API key when it is missing or rejected - #460
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The CLI said only "USEAGENT_API_KEY is not set" or "POST /api/runs -> HTTP 401", with no hint that keys are made in the web app. - A missing key now names Settings, API keys with a link on the server the CLI talks to (<base url>/settings#apikeys) and says to export the key. - A 401 says the server did not accept the key, names the server (so a key made on another server is easy to spot) and gives the same link. A 403 says the key was accepted but the request was refused, and points at the key's workspace instead of calling the key invalid. - The bin's single failure funnel maps errors through toCliError, so run, status and fan all print one line and exit 1. fan, whose dispatches never throw, fails once with the message when every dispatch was refused, rather than writing one dispatch_error line per task; a batch where some tasks went through keeps its results. - The MCP server returns the same message as the tool error, so a local agent sees the next step too. To let fan tell a refused key from a bad task without reading the message, a failed dispatchMany outcome now carries the HTTP status when the server answered. The CLI README and the CLI docs page describe the messages. Closes useagenthq#255
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #255
The CLI said only "USEAGENT_API_KEY is not set" or "POST /api/runs -> HTTP 401", with no hint that keys are made in Settings, API keys.
What it prints now
All three exit 1. The link and the server name come from
USEAGENT_BASE_URL, so a self-hosted server points at its own Settings page. The 401 line names the server, which makes a key from another server easy to spot. The 403 line never calls the key invalid.What changed
packages/clierrors.ts:apiKeysUrl(baseUrl)builds<base url>/settings#apikeys.apiKeyFailure(status, baseUrl)writes the 401 and 403 messages, and returns null for any other status.toCliError(error, baseUrl)turns any failure into theCliErrorthe bin prints.config.ts: the missing-key error links to Settings, API keys.resolveBaseUrlis split out so the bin can name the server when a request fails.bin.ts: the single catch handler goes throughtoCliError, sorun,statusandfanall print one line and exit with the right code.commands.ts:fandispatches never throw, so a rejected key used to come back as onedispatch_errorline per task. When every dispatch was refused over the key,fannow fails once with the message. A batch where some tasks went through keeps its results as before.mcp.ts: a tool that fails with a 401 or 403 returns the same message as its tool error, so a local agent sees the next step too.packages/agent-clientdispatchManyoutcome now carries the HTTPstatuswhen the server answered. That letsfantell a refused key from a bad task without matching message text. A network failure has no status.Docs: the CLI README and
docs-site/docs/getting-started/cli.mdxsay where keys are made and what the 401 and 403 messages mean.Tests
config.test.ts: the missing-key message, with the default and a custom base URL.errors.test.ts(new):toCliErrorpassing a usage error through with exit code 2commands.test.ts:runagainst a fake client that answers 401 fails with the rejected-key message and exit 1, printing nothing to stdoutstatuswith a 403 gets the refused-access message, not the new-key onefanfails once when every dispatch got a 401, and keeps the results of a batch where only some didmcp.test.ts:toolFailuregives the key message on a 401 and keeps any other failure's own message.agent-client/test/fleet.test.ts: a failed dispatch carries its status, and a network failure has none.Checks run locally with Bun 1.3.14:
cd packages/cli && bun run test: 63 pass, 0 failcd packages/agent-client && bun test test/fleet.test.ts: 19 pass, 0 failtsc --noEmit(TypeScript 5.9.3) inpackages/cliandpackages/agent-client: passesbun test scripts/agent-docs.test.ts: 5 passI also ran
bun packages/cli/src/bin.tsagainst a local stub server that answers 401 or 403.run,statusandfanprinted the messages above and exited 1, and with no key set it printed the missing-key line.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.