LifeGuide AI's Modal Client: Seven Fallbacks and an API Key in the Browser

LifeGuide AI is a React, TypeScript and Vite wellness app of mine under github.com/yethikrishna. I read src/services/modal.ts, a 507-line client for a Modal-hosted AI service. This post covers that file and does not judge the rest of the app.

What it calls

The class posts to paths under https://api.modal.com/v1/ for health analysis, sleep optimization, mental health, nutrition planning, audio generation and emergency assessment. Each request carries a function name, the inputs and a model config with a temperature, a max token count and a few flags such as crisis_detection. I could not verify that those endpoints exist in Modal's public API, so treat the file as a client for a service I did not test.

The key

The key is read from import.meta.env.VITE_MODAL_API_KEY. In Vite, variables with the VITE_ prefix are compiled into the client bundle, so a key set that way ships to every visitor. For a prototype that is understandable. For a deployed app it needs a small server that holds the key.

The fallbacks

Every method wraps its fetch in try and catch and returns a canned result on failure. The emergency fallback checks the text for four phrases: unconscious, not breathing, chest pain and severe bleeding. A match gives life_threatening and an advice to call 911. Anything else gives urgent. If the API returns text that is not JSON, the health parser returns risk level medium with generic advice.

The failure modes matter here. A network error, a missing key and a bad response all produce a calm, plausible answer, and nothing tells the user it was not the model. In a wellness app, and more so in an emergency screen, that is the wrong default.

What I would change

My opinion: the fallback should say plainly that the assistant is unavailable and show the emergency number, and it should never fill in a risk level. The 911 number is also US-specific, and I live in India, so the list needs the user's region. I would move the key to a server route before anyone else uses the app.

← back to the journal