Reference for getAiResponse — the core Google Gemini AI call that encodes a PDF, sends it with an instruction prompt, and returns a structured Feedback object.
Use this file to discover all available pages before exploring further.
getAiResponse is the core AI integration layer in Resume Check Karo. It receives a browser File object and a pre-built instruction prompt, base64-encodes the PDF, submits both to Google Gemini as a single multimodal user turn, and parses the model’s structured JSON response into a typed Feedback object. All AI-layer errors are caught internally so callers always receive a valid data shape.
The resume PDF to analyze. Internally, the function reads the file as an ArrayBuffer, converts it to a Node.js Buffer, and encodes it as a Base64 string before including it as an inlineData part in the Gemini request. The MIME type is hardcoded to "application/pdf".
The full text prompt that directs the model’s analysis. In normal usage this is built by prepareInstructions inside the analyzeResume server action — it includes the target company name, job title, full job description, and the five evaluation criteria the model must score.
Setting responseMimeType: "application/json" together with responseSchema activates Gemini’s controlled generation mode — the model is constrained to emit only valid JSON that matches the schema, eliminating markdown fences or free-form prose in the response.
Show Response parsing
After the API call, the raw text is extracted from response.text and passed to JSON.parse:
jsonOutput = response?.text ?? "";if (!jsonOutput) throw new Error("Empty response from AI model");return JSON.parse(jsonOutput) as Feedback;
If response.text is an empty string, the function throws before attempting to parse, which is caught by the surrounding try/catch and triggers the error fallback.
The schema enforces the exact shape of the model’s JSON output. The ATS section requires only type and tip on each tip item. All other sections (toneAndStyle, content, structure, skills) additionally require an explanation field on each tip.
If any step in the pipeline fails — the API call throws, response.text is empty, or JSON.parse raises a SyntaxError — the catch block logs a structured diagnostic object and returns createErrorFeedback() instead of propagating the exception.
// Logged to console on failure:{ error: err instanceof Error ? err.message : err, jsonOutput, // Raw text that failed to parse (if applicable) fileName: file.name, fileSize: file.size,}
The fallback object returned to the caller looks like this:
Because getAiResponse never re-throws AI errors, the analyzeResume server action will always receive a valid Feedback object. Zero scores across all sections are the signal that the AI call failed at runtime.
The model name is accessed with a TypeScript non-null assertion (process.env.GOOGLE_AI_MODEL!). If this environment variable is missing or misspelled at runtime, the Gemini SDK will throw immediately and the error fallback will be returned. Always verify GOOGLE_AI_MODEL is set in your .env.local (development) and your deployment environment before going live.