Skip to content

claude-agent-sdk swallows API error messages, returns unhelpful "Unknown error" #437

@beatboxchad

Description

@beatboxchad

My API key is from anthropic.com whereas my claude account is from claude.com. My code kept giving me this vague error:

 File "/usr/local/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/infrastructure/claude_reviewer.py", line 72, in review_mr
    async for message in query(prompt=prompt, options=options):
    ...<3 lines>...
                    response_text += block.text
  File "/usr/local/lib/python3.13/site-packages/claude_agent_sdk/query.py", line 123, in query
    async for message in client.process_query(
    ...<2 lines>...
        yield message
  File "/usr/local/lib/python3.13/site-packages/claude_agent_sdk/_internal/client.py", line 120, in process_query
    async for data in query.receive_messages():
        yield parse_message(data)
  File "/usr/local/lib/python3.13/site-packages/claude_agent_sdk/_internal/query.py", line 598, in receive_messages
    raise Exception(message.get("error", "Unknown error"))
Exception: Command failed with exit code 1 (exit code: 1)
Error output: Check stderr output for details

When I tested the API directly with cURL, I got a much more helpful message:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits."
  },
  "request_id": "req_011CWPC2UU2DQ7ND9gxnUSCt"
}

You should capture those API error messages and save us some more time :)

Thanks for this beautiful work, thrive on!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions