Skip to content

Make LLM Gateway errors name the gateway, not OpenAI - #17

Open
ericjohanson-langchain wants to merge 1 commit into
mainfrom
fix/gateway-error-clarity
Open

Make LLM Gateway errors name the gateway, not OpenAI#17
ericjohanson-langchain wants to merge 1 commit into
mainfrom
fix/gateway-error-clarity

Conversation

@ericjohanson-langchain

Copy link
Copy Markdown
Contributor

The gateway speaks the OpenAI API, so the agent uses the OpenAI SDK client to
reach it. When the gateway returns a 403, that client raises:

OpenAIPermissionDeniedError("Error code: 403 - {'error': 'API key has expired'}")

which names a service that was never contacted. The request goes to
gateway.smith.langchain.com with model anthropic/claude-haiku-…; nothing
reaches api.openai.com, and the credential at fault is a LangSmith key.

That misdirection cost real time twice in one session — it sends you to check
OpenAI billing and OpenAI keys when neither is involved.

Now:

RuntimeError: The LangSmith LLM Gateway at https://gateway.smith.langchain.com/v1
rejected the request: Error code: 403 - {'error': 'API key has expired'}. This is
a gateway/LangSmith credential problem, not OpenAI -- no request was made to
OpenAI. Check LLM_GATEWAY_API_KEY (or LANGSMITH_API_KEY), and note the gateway
only accepts Cloud keys, not a self-hosted instance's own key.

Only authentication and permission errors are restated; everything else passes
through untouched. Two tests cover both paths.

76 tests, lint, actionlint and bandit green.

The LangSmith LLM Gateway speaks the OpenAI API, so the agent talks to it with
the OpenAI SDK client. When the gateway returns 403, that client raises
OpenAIPermissionDeniedError -- naming a service that was never contacted.

This cost real debugging time twice, mine and a reviewer's: the message points
at OpenAI credentials while the actual problem is a LangSmith key against
gateway.smith.langchain.com, and no request reaches api.openai.com at all.

Wrap the gateway-backed model so authentication and permission failures are
restated with the gateway URL, the underlying message, an explicit note that
OpenAI is not involved, and which variable to check. Other errors pass through
untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant