API Reference: Enhancements
Relevant source files
The following files were used as context for generating this wiki page:The Enhancement API is the core AI-powered feature of the GUC Resume Enhancer. Its primary responsibility is to take the text content of an uploaded resume and use a third-party Large Language Model (LLM) to generate an improved version based on a selected enhancement type. This process is initiated by the user from the enhancement interface and handled by a dedicated server-side API route.
This system supports multiple AI providers, including OpenAI, Anthropic, and Google Gemini, and is designed to be extensible. The API manages the entire lifecycle of an enhancement, from receiving the request to calling the external AI service, storing the result, and handling potential errors.
Sources: README.md, api/enhance-resume/[id]/route.ts
API Endpoint: POST /api/enhance-resume/{id}
This is the main endpoint for initiating a resume enhancement. It is a server-side route that takes a resume ID and an enhancement type, processes the request, and returns the result.
| Property | Description |
|---|---|
| Path | /api/enhance-resume/{id} |
| Method | POST |
| Auth | Required. The user must have a valid session via NextAuth. |
| Max Duration | 300 seconds (5 minutes) to accommodate long-running AI processing tasks. |
| Response | JSON object containing the success status and the updated enhancement record. |
Sources: api/enhance-resume/[id]/route.ts:8-9, api/enhance-resume/[id]/route.ts:161-165, INTEGRATION_GUIDE.md
Request Body
The client must send a JSON object with the following property:
| Parameter | Type | Description |
|---|---|---|
enhancementType | string | A required string specifying the type of enhancement to perform. Must be one of the allowed types. |
Sources: api/enhance-resume/[id]/route.ts:167-171
Architecture and Data Flow
The enhancement process involves the frontend client, the Next.js backend API, the Prisma ORM connected to a database, and an external AI provider's API.
The following sequence diagram illustrates the complete flow from user action to completion.
This diagram shows the sequence of operations when a user requests a resume enhancement.
Sources: enhance/[id]/_components/enhance-interface.tsx:210-224, api/enhance-resume/[id]/route.ts:158-267
Internal API Logic
The POST handler in api/enhance-resume/[id]/route.ts follows a clear set of steps to process an enhancement request.
This flowchart details the internal logic of the enhancement API route, including validation, database interactions, and error handling.
Sources: api/enhance-resume/[id]/route.ts:158-280
Enhancement Types
The system supports a predefined set of enhancement types. Each type corresponds to a specific prompt sent to the LLM to guide the enhancement process.
Value (enhancementType) | Label (UI) | Description |
|---|---|---|
skills_certifications | Skills & Certifications | Highlight trade skills, licenses, and certifications |
project_experience | Project Experience | Showcase completed work and technical expertise |
client_quality | Client Success & Quality | Emphasize customer satisfaction and quality work |
Sources: enhance/[id]/_components/enhance-interface.tsx:55-76, api/enhance-resume/[id]/route.ts:173-179
The API uses a whitelist to ensure only these allowed types are processed.
Sources: api/enhance-resume/[id]/route.ts:158-159
AI Provider Integration
The API is designed to work with multiple AI providers. The selection of the provider is determined by the user's active UserApiKey record in the database.
Sources: api/enhance-resume/[id]/route.ts:195-203, api/enhance-resume/[id]/route.ts:221-223
Provider-Specific Helpers
The route contains dedicated helper functions for communicating with each supported AI provider's API:
enhanceWithOpenAI(apiKey, model, content, enhancementType)enhanceWithAnthropic(apiKey, model, content, enhancementType)enhanceWithGemini(apiKey, model, content, enhancementType)
A switch statement calls the appropriate helper based on the provider field from the user's API key.
Sources: api/enhance-resume/[id]/route.ts:13-156, api/enhance-resume/[id]/route.ts:223-235
Database Schema
The enhancement feature relies on two primary database models: Resume and ResumeEnhancement. A single resume can have multiple enhancements.
This ER diagram shows the one-to-many relationship between the Resume and ResumeEnhancement tables.
Sources: README.md, api/enhance-resume/[id]/route.ts:206-216, api/resumes/upload/route.ts:107-118
ResumeEnhancement Model
This table stores the results of each AI enhancement job.
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the enhancement. |
resumeId | String | Foreign key linking to the Resume table. |
enhancementType | String | The type of enhancement performed (e.g., skills_certifications). |
enhancedContent | String | The AI-generated text content. |
llmProvider | String | The AI provider used (e.g., openai, anthropic). |
status | String | The status of the job (processing, completed, error). |
enhancementNotes | String | Stores error messages or other notes related to the job. |
Sources: api/enhance-resume/[id]/route.ts:206-216, api/enhance-resume/[id]/route.ts:238-245, api/enhance-resume/[id]/route.ts:249-255
Error Handling
The API includes a try...catch block to manage failures during the AI enhancement process. If an error occurs when calling the external AI provider:
- The
ResumeEnhancementrecord's status is updated toerror. - The error message from the AI provider is saved in the
enhancementNotesfield. - A system log entry is created for the failure.
- A
500 Internal Server Errorresponse is sent to the client.
Sources: api/enhance-resume/[id]/route.ts:247-265
Related Endpoint: GET /api/download-resume/{id}
Once an enhancement is complete, the user can download it as a PDF. This is handled by a separate API endpoint that references the ResumeEnhancement ID.
- Path:
/api/download-resume/{id}(whereidis theResumeEnhancementID) - Method:
GET - Functionality:
- Fetches the specified
ResumeEnhancementrecord. - Uses the
jsPDFlibrary to generate a new PDF document from theenhancedContent. - Returns the generated PDF as a file download.
- Fetches the specified
Sources: api/download-resume/[id]/route.ts, enhance/[id]/_components/enhance-interface.tsx:288-292
Summary
The Enhancement API is a robust system that orchestrates the interaction between the user, the application's database, and external AI services. It securely handles user data and API keys, manages the state of enhancement jobs, and provides clear feedback and error handling. Its modular design with provider-specific helpers allows for easy maintenance and future expansion to include other AI models or enhancement types.