Skip to main content
This endpoint retrieves a user’s profile image URL from Clerk’s user management system.

Endpoint

GET /api/user-image

Request

Query parameters

userId
string
required
The Clerk user ID to retrieve the image for.

Response

imageUrl
string or null
The user’s profile image URL if they have one, or null if no image is set.

Example

Request

curl https://wrkks.vercel.app/api/user-image?userId=user_2abc123def456 \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "imageUrl": "https://img.clerk.com/eyJ0eXBlIjoicHJveHkiLCJzcmMiOiJodHRwczovL2ltYWdlcy51bnNwbGFzaC5jb20vcGhvdG8tMTUwMDQ4NDM5MzU4Nj93PTEwMDAifQ"
}
Or if the user has no image:
{
  "imageUrl": null
}

Error responses

400 Bad Request

Returned when the userId query parameter is missing:
{
  "msg": "Missing userId"
}

404 Not Found

Returned when the user is not found in Clerk:
{
  "msg": "User not found"
}

Implementation

The endpoint uses Clerk’s API to fetch user information:
const client = await clerkClient();
const user = await client.users.getUser(userId);

return NextResponse.json({
  imageUrl: user.hasImage ? user.imageUrl : null,
});
Source: /app/api/user-image/route.ts:4-21

Usage

This endpoint is primarily used by the frontend to display user profile images in the resume editor and preview components. It ensures that profile images are fetched securely through the backend rather than exposing Clerk API keys to the client.

Build docs developers (and LLMs) love