Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hud/agents/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import copy
import logging
import requests
from typing import TYPE_CHECKING, Any, ClassVar, cast

from anthropic import AsyncAnthropic, BadRequestError
from anthropic import AsyncAnthropic, BadRequestError, AuthenticationError
from anthropic.types.beta import BetaContentBlockParam, BetaImageBlockParam, BetaTextBlockParam

import hud
Expand Down Expand Up @@ -209,6 +210,8 @@ async def get_response(self, messages: list[BetaMessageParam]) -> AgentResponse:
raise
else:
raise
except AuthenticationError:
raise ValueError("Anthropic API key is set but is not valid.")

messages.append(
cast(
Expand Down
22 changes: 13 additions & 9 deletions hud/agents/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from __future__ import annotations

import logging
import requests
from typing import Any, ClassVar, Literal

import mcp.types as types
from openai import AsyncOpenAI
from openai import AsyncOpenAI, AuthenticationError
from openai.types.responses import (
ResponseComputerToolCall,
ResponseInputMessageContentListParam,
Expand Down Expand Up @@ -175,14 +176,17 @@ async def get_response(self, messages: ResponseInputMessageContentListParam) ->

input_param: ResponseInputParam = [{"role": "user", "content": input_content}] # type: ignore[reportUnknownMemberType]

response = await self.openai_client.responses.create(
model=self.model,
tools=[computer_tool],
input=input_param,
instructions=self.system_prompt,
truncation="auto",
reasoning={"summary": "auto"}, # type: ignore[arg-type]
)
try:
response = await self.openai_client.responses.create(
model=self.model,
tools=[computer_tool],
input=input_param,
instructions=self.system_prompt,
truncation="auto",
reasoning={"summary": "auto"}, # type: ignore[arg-type]
)
except AuthenticationError:
raise ValueError("OpenAI API key is set but is not valid.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent Error Handling Across API Calls

The AuthenticationError handling for openai_client.responses.create() is only applied to the initial conversation path. The identical API call in the else branch for follow-up steps lacks this, causing inconsistent error behavior.

Fix in Cursor Fix in Web

else:
# Follow-up step - check if this is user input or tool result
latest_message = messages[-1] if messages else {}
Expand Down
Loading