Skip to content

POST: /api/chat doesn't reply. #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
luckiman opened this issue Apr 4, 2025 · 13 comments
Open

POST: /api/chat doesn't reply. #907

luckiman opened this issue Apr 4, 2025 · 13 comments

Comments

@luckiman
Copy link

luckiman commented Apr 4, 2025

Image
I forked project in local and set all environment variables. but it occurs error while sending message. What's wrong?

@generativelabs
Copy link

I ran into the same thing. The app/(chat)/api/chat/route.ts is eating the meaningful error, if you add:

  } catch (error) {
    console.error("[DEBUG] API error:", error);
    return new Response('An error occurred while processing your request!', {
      status: 404,
    });

you'll see what the problem is. For me, it was I didn't have XAI_API_KEY defined. The latest versions use xAI as you can see in providers.ts

@luckiman
Copy link
Author

luckiman commented Apr 5, 2025

I got a xAI api key and set it in local.env. how to validate that api key?

@generativelabs
Copy link

generativelabs commented Apr 5, 2025

how to validate that api key?

Set a breakpoint on that exception or add debug message shown above to validate / rule out an invalid key.

@cssagogo
Copy link

cssagogo commented Apr 5, 2025

Running into the same issue.

@luckiman
Copy link
Author

luckiman commented Apr 6, 2025

Image

I checked the point occuring issue. It caused at generateTitleFromUserMessage in /api/chat/route.ts.
how to solve the "server is not available"?
Can't I use free xAi free api key?

@arthtyagi
Copy link

You need credits on xAI API key.

@luckiman
Copy link
Author

How to get credits on xAI API key? I have already got a xAI_API_KEY in https://console.x.ai/.
But it occurs above error. why and how to fix it?

@zzkkui
Copy link

zzkkui commented Apr 12, 2025

I am using deepseek and my deepseek has a credit limit. When I start it, the command line reports an error and chat returns 404.

before chat
Image

Image

Image

Image

The key used here is usable because I can chat normally in other places

@luckiman
Copy link
Author

You mean that I should use google or deepseek api key, not a xAi key?

@GitTom
Copy link

GitTom commented Apr 17, 2025

Most of the other providers are fairly generous with their free tiers so you don't have to get into paying.

Here's a diff of changes I made to providers.ts and the package.json to switch this code template back to OpenAI.

(If you aren't familiar with this diff format then just give this to your LLM and it will help you understand it, validate it, and apply it.)

diff --git a/lib/ai/providers.ts b/lib/ai/providers.ts
index 810c329..c10b211 100644
--- a/lib/ai/providers.ts
+++ b/lib/ai/providers.ts
@@ -3,7 +3,7 @@ import {
   extractReasoningMiddleware,
   wrapLanguageModel,
 } from 'ai';
-import { xai } from '@ai-sdk/xai';
+import { openai } from '@ai-sdk/openai';
 import { isTestEnvironment } from '../constants';
 import {
   artifactModel,
@@ -23,15 +23,16 @@ export const myProvider = isTestEnvironment
     })
   : customProvider({
       languageModels: {
-        'chat-model': xai('grok-2-1212'),
+        'chat-model': openai('gpt-4o-mini'),
         'chat-model-reasoning': wrapLanguageModel({
-          model: xai('grok-3-mini-beta'),
+          model: openai('o3-mini'),
           middleware: extractReasoningMiddleware({ tagName: 'think' }),
         }),
-        'title-model': xai('grok-2-1212'),
-        'artifact-model': xai('grok-2-1212'),
+        'title-model': openai('o3-mini'),
+        'artifact-model': openai('o3-mini'),
       },
       imageModels: {
-        'small-model': xai.image('grok-2-image'),
+       'small-model': openai.image('dall-e-2'),
+       'large-model': openai.image('dall-e-3'),
       },
     });

diff --git a/package.json b/package.json
index a48d3e3..6236ef9 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
   },
   "dependencies": {
     "@ai-sdk/react": "^1.2.8",
-    "@ai-sdk/xai": "^1.2.10",
+    "@ai-sdk/openai": "^1.3.10",
     "@codemirror/lang-javascript": "^6.2.2",
     "@codemirror/lang-python": "^6.1.6",
     "@codemirror/state": "^6.5.0",
@@ -104,4 +104,4 @@
     "typescript": "^5.6.3"
   },
   "packageManager": "pnpm@9.12.3"
-}
+}

@luckiman
Copy link
Author

I updated code with openAI model and added a OPENAI_API_KEY. But it occurs a similar error.

Image

@blexo
Copy link

blexo commented Apr 28, 2025

Also... they need to update their documentation...

@yuxizhe
Copy link

yuxizhe commented May 27, 2025

you can add console.error at app/(chat)/api/chat/route.ts line 223 & 239

https://github.com/vercel/ai-chatbot/blob/main/app/(chat)/api/chat/route.ts#L223

Image Image

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

No branches or pull requests

8 participants