Skip to content

api key dialog#31

Merged
ctate merged 2 commits intomainfrom
ctate/api-key-dialog
Oct 11, 2025
Merged

api key dialog#31
ctate merged 2 commits intomainfrom
ctate/api-key-dialog

Conversation

@ctate
Copy link
Collaborator

@ctate ctate commented Oct 11, 2025

No description provided.

@vercel
Copy link
Contributor

vercel bot commented Oct 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
coding-agent-platform Ready Ready Preview Comment Oct 11, 2025 4:41pm

Comment on lines +273 to +295
const response = await fetch(`/api/api-keys/check?agent=${selectedAgent}&model=${selectedModel}`)
const data = await response.json()

if (!data.hasKey) {
// Show error message with provider name
const providerNames: Record<string, string> = {
anthropic: 'Anthropic',
openai: 'OpenAI',
cursor: 'Cursor',
gemini: 'Gemini',
aigateway: 'AI Gateway',
}
const providerName = providerNames[data.provider] || data.provider

toast.error(`${providerName} API key required`, {
description: `Please add your ${providerName} API key to use the ${data.agentName} agent with this model.`,
action: {
label: 'Add API Key',
onClick: () => setShowApiKeysDialog(true),
},
})
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing response status check before accessing API response data, causing error responses to show "undefined API key required" instead of proper error messages.

View Details
📝 Patch Details
diff --git a/components/task-form.tsx b/components/task-form.tsx
index dfe5c76..bab118f 100644
--- a/components/task-form.tsx
+++ b/components/task-form.tsx
@@ -271,6 +271,15 @@ export function TaskForm({
       // Check if API key is required and available for the selected agent and model
       try {
         const response = await fetch(`/api/api-keys/check?agent=${selectedAgent}&model=${selectedModel}`)
+        
+        if (!response.ok) {
+          const error = await response.json()
+          toast.error('Failed to validate API key availability', {
+            description: error.error || 'An error occurred while checking API key availability',
+          })
+          return
+        }
+
         const data = await response.json()
 
         if (!data.hasKey) {

Analysis

Missing response status check in API key validation causes misleading error messages

What fails: components/task-form.tsx handleSubmit() calls response.json() without checking response.ok, causing error responses to be processed as valid data

How to reproduce:

# API returns error: { error: 'Invalid agent' } with status 400
# Current code accesses data.hasKey, data.provider, data.agentName without checking response.ok

Result: When API returns { error: 'Invalid agent' } (status 400), data.hasKey is undefined, so the code shows toast: "undefined API key required" with description "Please add your undefined API key to use the undefined agent with this model."

Expected: Should check response.ok first (following Fetch API pattern used in 21 other locations in codebase including line 251 of same file), show proper error message from API response

@ctate ctate merged commit 2d20956 into main Oct 11, 2025
4 checks passed
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