Error updating api key

I am facing an error while trying to update the api key, my code:
import type { IncomingHttpHeaders } from 'node:http'
import { auth } from '../../lib/auth.ts'
import type { UpdateApiKeyBody } from '../../schemas/api-keys/index.ts'

export async function updateApiKey(
userId: string,
keyId: string,
body: UpdateApiKeyBody,
headers: IncomingHttpHeaders
) {
console.log(body)
const apiKey = await auth.api.updateApiKey({
body: {
...body,
keyId,
},
headers,
})
console.log('apiKey', apiKey)

return apiKey
}
import type { IncomingHttpHeaders } from 'node:http'
import { auth } from '../../lib/auth.ts'
import type { UpdateApiKeyBody } from '../../schemas/api-keys/index.ts'

export async function updateApiKey(
userId: string,
keyId: string,
body: UpdateApiKeyBody,
headers: IncomingHttpHeaders
) {
console.log(body)
const apiKey = await auth.api.updateApiKey({
body: {
...body,
keyId,
},
headers,
})
console.log('apiKey', apiKey)

return apiKey
}
body: { name: 'teste', enabled: true, rateLimitEnabled: false } error: [APIError: The property you're trying to set can only be set from the server auth instance only.] { status: 'BAD_REQUEST', body: { code: 'THE_PROPERTY_YOURE_TRYING_TO_SET_CAN_ONLY_BE_SET_FROM_THE_SERVER_AUTH_INSTANCE_ONLY', message: "The property you're trying to set can only be set from the server auth instance only." }, headers: {}, statusCode: 400 } my typing of body:
type UpdateApiKeyBody = {
name?: string | undefined;
refillInterval?: number | undefined;
refillAmount?: number | undefined;
enabled?: boolean | undefined;
rateLimitEnabled?: boolean | undefined;
rateLimitTimeWindow?: number | undefined;
rateLimitMax?: number | undefined;
remaining?: number | undefined;
expiresIn?: number | null | undefined;
metadata?: Record<string, any> | null | undefined;
permissions?: Record<string, string[]> | null | undefined;
}
type UpdateApiKeyBody = {
name?: string | undefined;
refillInterval?: number | undefined;
refillAmount?: number | undefined;
enabled?: boolean | undefined;
rateLimitEnabled?: boolean | undefined;
rateLimitTimeWindow?: number | undefined;
rateLimitMax?: number | undefined;
remaining?: number | undefined;
expiresIn?: number | null | undefined;
metadata?: Record<string, any> | null | undefined;
permissions?: Record<string, string[]> | null | undefined;
}
3 Replies
Ping
Ping2w ago
Try seeing if you can run that endpoint without headers
<yanzaum/>
<yanzaum/>OP7d ago
no headers
[APIError: Unauthorized or invalid session] {
status: 'UNAUTHORIZED',
body: {
code: 'UNAUTHORIZED_OR_INVALID_SESSION',
message: 'Unauthorized or invalid session'
},
headers: {},
statusCode: 401
}
[APIError: Unauthorized or invalid session] {
status: 'UNAUTHORIZED',
body: {
code: 'UNAUTHORIZED_OR_INVALID_SESSION',
message: 'Unauthorized or invalid session'
},
headers: {},
statusCode: 401
}
no headers and user id
Argument `where` of type ApikeyWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.] {
status: 'INTERNAL_SERVER_ERROR',
body: {
code: 'INVALID_PRISMAAPIKEYUPDATE_INVOCATION__WHERE_____AND_______________ID_LJTQL4AQBJSQ6NFQSOU3XF1OHZK53HPN____________________USERID_AEDJTYLWWXXHLXQW2WLJ8453EGURFTML_____________ID_STRING___OR_APIKEYWHEREINPUT___NOT_APIKEYWHEREINPUT__APIKEYWHEREINPUT___NAME_STRINGNULLABLEFILTER__STRING__NULL___START_STRINGNULLABLEFILTER__STRING__NULL___PREFIX_STRINGNULLABLEFILTER__STRING__NULL___KEY_STRINGFILTER__STRING___USERID_STRINGFILTER__STRING___REFILLINTERVAL_INTNULLABLEFILTER__INT__NULL___REFILLAMOUNT_INTNULLABLEFILTER__INT__NULL___LASTREFILLAT_DATETIMENULLABLEFILTER__DATETIME__NULL___ENABLED_BOOLNULLABLEFILTER__BOOLEAN__NULL___RATELIMITENABLED_BOOLNULLABLEFILTER__BOOLEAN__NULL___RATELIMITTIMEWINDOW_INTNULLABLEFILTER__INT__NULL___RATELIMITMAX_INTNULLABLEFILTER__INT__NULL___REQUESTCOUNT_INTNULLABLEFILTER__INT__NULL___REMAINING_INTNULLABLEFILTER__INT__NULL___LASTREQUEST_DATETIMENULLABLEFILTER__DATETIME__NULL___EXPIRESAT_DATETIMENULLABLEFILTER__DATETIME__NULL___CREATEDAT_DATETIMEFILTER__DATETIME___UPDATEDAT_DATETIMEFILTER__DATETIME___PERMISSIONS_STRINGNULLABLEFILTER__STRING__NULL___METADATA_STRINGNULLABLEFILTER__STRING__NULL___USER_USERSCALARRELATIONFILTER__USERWHEREINPUT____DATA_____NAME_TESTE____ENABLED_TRUE____RATELIMITENABLED_FALSE____REMAINING_NULL____LASTREQUEST_NEW_DATE20250822T224109713Z__ARGUMENT_WHERE_OF_TYPE_APIKEYWHEREUNIQUEINPUT_NEEDS_AT_LEAST_ONE_OF_ID_ARGUMENTS_AVAILABLE_OPTIONS_ARE_MARKED_WITH_',
message: '\n' +
'Invalid `prisma.apikey.update()` invocation:\n' +
'\n' +
'{\n' +
' where: {\n' +
' AND: [\n' +
' {\n' +
' id: "lJTql4aQBJSq6NfqsOU3xF1oHzK53HpN"\n' +
' },\n' +
' {\n' +
' userId: "aeDJtyLWwXxHlxQw2wLJ8453EGURFTMl"\n' +
' }\n' +
' ],\n' +
'? id?: String,\n' +
'? OR?: ApikeyWhereInput[],\n' +
'? NOT?: ApikeyWhereInput | ApikeyWhereInput[],\n' +
'? name?: StringNullableFilter | String | Null,\n' +
'? start?: StringNullableFilter | String | Null,\n' +
'? prefix?: StringNullableFilter | String | Null,\n' +
'? key?: StringFilter | String,\n' +
'? userId?: StringFilter | String,\n' +
'? refillInterval?: IntNullableFilter | Int | Null,\n' +
'? refillAmount?: IntNullableFilter | Int | Null,\n' +
'? lastRefillAt?: DateTimeNullableFilter | DateTime | Null,\n' +
'? enabled?: BoolNullableFilter | Boolean | Null,\n' +
'? rateLimitEnabled?: BoolNullableFilter | Boolean | Null,\n' +
'? rateLimitTimeWindow?: IntNullableFilter | Int | Null,\n' +
'? rateLimitMax?: IntNullableFilter | Int | Null,\n' +
'? requestCount?: IntNullableFilter | Int | Null,\n' +
'? remaining?: IntNullableFilter | Int | Null,\n' +
'? lastRequest?: DateTimeNullableFilter | DateTime | Null,\n' +
'? expiresAt?: DateTimeNullableFilter | DateTime | Null,\n' +
'? createdAt?: DateTimeFilter | DateTime,\n' +
'? updatedAt?: DateTimeFilter | DateTime,\n' +
'? permissions?: StringNullableFilter | String | Null,\n' +
'? metadata?: StringNullableFilter | String | Null,\n' +
'? user?: UserScalarRelationFilter | UserWhereInput\n' +
' },\n' +
' data: {\n' +
' name: "teste",\n' +
' enabled: true,\n' +
' rateLimitEnabled: false,\n' +
' remaining: null,\n' +
' lastRequest: new Date("2025-08-22T22:41:09.713Z")\n' +
' }\n' +
'}\n' +
'\n' +
'Argument `where` of type ApikeyWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.'
},
headers: {},
statusCode: 500
}
Argument `where` of type ApikeyWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.] {
status: 'INTERNAL_SERVER_ERROR',
body: {
code: 'INVALID_PRISMAAPIKEYUPDATE_INVOCATION__WHERE_____AND_______________ID_LJTQL4AQBJSQ6NFQSOU3XF1OHZK53HPN____________________USERID_AEDJTYLWWXXHLXQW2WLJ8453EGURFTML_____________ID_STRING___OR_APIKEYWHEREINPUT___NOT_APIKEYWHEREINPUT__APIKEYWHEREINPUT___NAME_STRINGNULLABLEFILTER__STRING__NULL___START_STRINGNULLABLEFILTER__STRING__NULL___PREFIX_STRINGNULLABLEFILTER__STRING__NULL___KEY_STRINGFILTER__STRING___USERID_STRINGFILTER__STRING___REFILLINTERVAL_INTNULLABLEFILTER__INT__NULL___REFILLAMOUNT_INTNULLABLEFILTER__INT__NULL___LASTREFILLAT_DATETIMENULLABLEFILTER__DATETIME__NULL___ENABLED_BOOLNULLABLEFILTER__BOOLEAN__NULL___RATELIMITENABLED_BOOLNULLABLEFILTER__BOOLEAN__NULL___RATELIMITTIMEWINDOW_INTNULLABLEFILTER__INT__NULL___RATELIMITMAX_INTNULLABLEFILTER__INT__NULL___REQUESTCOUNT_INTNULLABLEFILTER__INT__NULL___REMAINING_INTNULLABLEFILTER__INT__NULL___LASTREQUEST_DATETIMENULLABLEFILTER__DATETIME__NULL___EXPIRESAT_DATETIMENULLABLEFILTER__DATETIME__NULL___CREATEDAT_DATETIMEFILTER__DATETIME___UPDATEDAT_DATETIMEFILTER__DATETIME___PERMISSIONS_STRINGNULLABLEFILTER__STRING__NULL___METADATA_STRINGNULLABLEFILTER__STRING__NULL___USER_USERSCALARRELATIONFILTER__USERWHEREINPUT____DATA_____NAME_TESTE____ENABLED_TRUE____RATELIMITENABLED_FALSE____REMAINING_NULL____LASTREQUEST_NEW_DATE20250822T224109713Z__ARGUMENT_WHERE_OF_TYPE_APIKEYWHEREUNIQUEINPUT_NEEDS_AT_LEAST_ONE_OF_ID_ARGUMENTS_AVAILABLE_OPTIONS_ARE_MARKED_WITH_',
message: '\n' +
'Invalid `prisma.apikey.update()` invocation:\n' +
'\n' +
'{\n' +
' where: {\n' +
' AND: [\n' +
' {\n' +
' id: "lJTql4aQBJSq6NfqsOU3xF1oHzK53HpN"\n' +
' },\n' +
' {\n' +
' userId: "aeDJtyLWwXxHlxQw2wLJ8453EGURFTMl"\n' +
' }\n' +
' ],\n' +
'? id?: String,\n' +
'? OR?: ApikeyWhereInput[],\n' +
'? NOT?: ApikeyWhereInput | ApikeyWhereInput[],\n' +
'? name?: StringNullableFilter | String | Null,\n' +
'? start?: StringNullableFilter | String | Null,\n' +
'? prefix?: StringNullableFilter | String | Null,\n' +
'? key?: StringFilter | String,\n' +
'? userId?: StringFilter | String,\n' +
'? refillInterval?: IntNullableFilter | Int | Null,\n' +
'? refillAmount?: IntNullableFilter | Int | Null,\n' +
'? lastRefillAt?: DateTimeNullableFilter | DateTime | Null,\n' +
'? enabled?: BoolNullableFilter | Boolean | Null,\n' +
'? rateLimitEnabled?: BoolNullableFilter | Boolean | Null,\n' +
'? rateLimitTimeWindow?: IntNullableFilter | Int | Null,\n' +
'? rateLimitMax?: IntNullableFilter | Int | Null,\n' +
'? requestCount?: IntNullableFilter | Int | Null,\n' +
'? remaining?: IntNullableFilter | Int | Null,\n' +
'? lastRequest?: DateTimeNullableFilter | DateTime | Null,\n' +
'? expiresAt?: DateTimeNullableFilter | DateTime | Null,\n' +
'? createdAt?: DateTimeFilter | DateTime,\n' +
'? updatedAt?: DateTimeFilter | DateTime,\n' +
'? permissions?: StringNullableFilter | String | Null,\n' +
'? metadata?: StringNullableFilter | String | Null,\n' +
'? user?: UserScalarRelationFilter | UserWhereInput\n' +
' },\n' +
' data: {\n' +
' name: "teste",\n' +
' enabled: true,\n' +
' rateLimitEnabled: false,\n' +
' remaining: null,\n' +
' lastRequest: new Date("2025-08-22T22:41:09.713Z")\n' +
' }\n' +
'}\n' +
'\n' +
'Argument `where` of type ApikeyWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.'
},
headers: {},
statusCode: 500
}
Ravi
Ravi18h ago
@Matt

Did you find this page helpful?