This is an excellent update to AstroLens. Adding the AI explanation feature elevates the project from a simple data viewer to an interactive learning tool, which hits the “Technicality” and “Storytelling” marks the Stardance Shipwrights are looking for.
Here is a Devlog entry detailing the AI integration, structured to clearly show progress, technical implementation, and the user experience.
🚀 Devlog Update: The AI Knows Space! (Integrating the Hack Club AI Proxy)
The Goal:
The raw NASA APIs (like APOD and DONKI) are amazing, but the data is often incredibly dense and full of scientific jargon. I wanted AstroLens to not just show space data, but explain it. The goal was to build a persistent AI Chat layer that uses real-time NASA data as context to answer user questions simply.
The Implementation:
I integrated Hack Club’s free AI API (ai.hackclub.com/proxy/v1/chat/completions) directly into the React frontend.
The API Route: I created a dedicated ai.js service file to handle the fetch request to the proxy, passing my VITE_HACKCLUB_AI_KEY securely via the Authorization header.
Context Injection: The real magic is in the context. When a user clicks “Explain with AI” on the Asteroid page, the code doesn’t just ask the AI a generic question. It programmatically injects the live data array (e.g., “There are 12 asteroids passing Earth today, 2 are hazardous…”) into the hidden system prompt before asking the user’s question.
Model Selection: After some testing with gemini-2.5-flash, I found that the qwen/qwen3-32b model returned slightly faster and more concise plain-English explanations for the astronomy queries, so I locked that in as the primary model.
The Struggle (and the Fix):
Getting this working locally was smooth, but deploying it to Vercel completely broke the AI feature—it just threw a generic “AI unavailable” error.
It took some debugging, but I realized the issue was my .env file. I correctly had .env listed in .gitignore (security first!), which meant the API key never pushed to GitHub. Since Vercel pulls from GitHub, it had no key. I fixed it by manually adding VITE_HACKCLUB_AI_KEY to the Vercel project’s Environment Variables dashboard and running a fresh redeploy.
The Result:
AstroLens now features a working “🤖 Explain with AI” button on the data pages. If you look at an APOD image of a Wolf-Rayet star and don’t know what that means, the AI will now break it down into simple terms, right there in the dashboard.