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
446

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
david_knaack
Associate
Associate
0 Likes

This question was resolved in GitHub issue #26.

The problem was a port conflict with SAP Business Application Studio (3000/3001). The application already occupies those ports, so the UI proxy hits an HTML error page instead of the agent route.

The latest version of the demo on GitHub improves the error messaging to make port conflicts more obvious.

To resolve the conflict, update the ports used by the mock server and agent server.

  1. Update the exercises/javascript/app/mock-server/src/server.ts file to set the mock server port to 3005 (or another free port).
// exercises/javascript/app/mock-server/src/server.ts
-const port = process.env.PORT || 3001;
+const port = process.env.PORT || 3005;
  1. Update the exercises/javascript/app/agent/src/setup.ts file to point the base URL to port 3005.
// exercises/javascript/app/agent/src/setup.ts
export const BASE_URL_API_PURCHASEORDER_PROCESS_SRV =
`http://localhost:3005/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/`;
  1. Update the exercises/javascript/app/agent/src/server.ts file to set the agent server port to 3006 (or another free port).
// exercises/javascript/app/agent/src/server.ts
-const port = process.env.PORT || 3001;
+const port = process.env.PORT || 3006;
  1. Update the exercises/javascript/app/ui/vite.config.ts file to point the UI proxy to port 3006.
// exercises/javascript/app/ui/vite.config.ts
- target: 'http://localhost:3001',
+ target: 'http://localhost:3006',

After these changes, the preview endpoint should route correctly, and the agent call should stop returning “HTML/404”.