Skip to main content
PUT
/
api
/
ai
/
key
Save Gemini API Key
curl --request PUT \
  --url https://api.example.com/api/ai/key \
  --header 'Content-Type: application/json' \
  --data '
{
  "key": "<string>"
}
'
Stores or updates the Gemini API key for the authenticated user. The key is encrypted using AES-256 before being stored in the database.

Authentication

Requires Bearer token authentication.

Request Body

key
string
required
The Gemini API key to store. Cannot be blank.

Response

Returns 204 No Content on success with an empty response body.

Example Request

curl -X PUT https://api.example.com/api/ai/key \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "AIzaSyD..."
  }'

Example Response

HTTP/1.1 204 No Content

Error Responses

400 Bad Request
The API key is missing or blank
{
  "error": "Bad Request",
  "message": "API key cannot be empty"
}
401 Unauthorized
Authentication token is missing or invalid
{
  "error": "Unauthorized",
  "message": "Invalid or missing authentication token"
}
404 Not Found
The user account was not found
{
  "error": "Not Found",
  "message": "User not found"
}

Security

  • API keys are encrypted using AES-256 encryption via the EncryptionService before storage
  • Keys are never exposed in API responses
  • The encryption key is managed securely by the application
  • If you need to obtain a Gemini API key, visit Google AI Studio

Build docs developers (and LLMs) love