cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue with AI160 JavaScript Exercise – /api/agent/trigger-agent returning HTML instead of JSON

MKM
Active Participant
0 Likes
447

Hi SAP Community,

I’m currently working through the excellent TechEd 2025 AI160 – “Build Your Own AI Agent-Based Solution with the Generative AI Hub hands-on, specifically the JavaScript exercise.

My setup:

  • Productive SAP AI Core instance

  • Provisioned in SAP BTP Cockpit (extended plan)

  • Service keys fully configured

  • Running the tutorial using npm run tutorial in SAP Business Application Studio

The UI (port 3002), Agent (port 3001), and Mock Server (port 3000) all start successfully.

However, when triggering the agent from the UI, I get the following error in the browser:

Error: Failed to execute 'json' on 'Response':
Unexpected token '<', "<!DOCTYPE "... is not valid JSON

 In the Network tab, I see:

GET /api/agent/trigger-agent → 404 / HTML response

I verified:

  • Vite proxy is configured to forward /apihttp://localhost:3001

  • Agent server is running on port 3001

  • Endpoint /api/agent/trigger-agent exists in server.ts

  • x-thread-id header is being sent from the UI

Despite this, the response is sometimes HTML (404 / error page) instead of JSON, causing the parsing error.

Has anyone faced a similar issue with AI160 JavaScript exercises?
Is there anything specific to check regarding routing, proxying, or error handling when using productive AI Core instances?

Any guidance would be greatly appreciated. @ZhongpinWang@deekshasinha

Thank you!

View Entire Topic
MKM
Active Participant
0 Likes

@gregorw  Curl works perfectly.. only SAP AI Core deployment doesn't support /chat/completionsendpoint.

curl -v -i -X POST \
  "https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com/v2/inference/deployments/d48a78b0811caa3b/chat/completions" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "AI-Resource-Group: <123>" \
  -H "X-Tenant: e125da77-03b4-4f88-ad8c-d5055c2cfaea" \
  -d '{"messages":[{"role":"user","content":"Hello!"}],"max_tokens":200}'

When running the agent code (exercises/javascript/app/agent.ts or po-agents.js), I encounter this TypeScript compilation error:

Argument of type 'BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]' is not assignable to parameter of type 'BaseLanguageModelInput'. Type 'BaseMessage<MessageStructure<MessageToolSet>, MessageType>[]' is not assignable to type 'BaseMessageLike[]'. [... full error in comment below]

Error location:

async function callModel({ messages }: typeof MessagesAnnotation.State) { const response = await modelWithTools.invoke(messages); // ❌ Error here return { messages: [response] }; }

MKM_0-1771590157842.png

Happy to provide more details or test fixes! Would love to see this resolved for productive SAP AI Core usage.

Thanks for the great work!
Manoj