# User Management

Operations for user authentication and account management

## Generate a new API key

> Generates a new API key for the authenticated user (replaces existing key)

```json
{"openapi":"3.0.3","info":{"title":"DeepWriter API","version":"2.0.0"},"tags":[{"name":"User Management","description":"Operations for user authentication and account management"}],"servers":[{"url":"/api","description":"API base path"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"JWT token for user session authentication."}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"A message describing the error"}},"required":["error"]}}},"paths":{"/generateApiKey":{"post":{"summary":"Generate a new API key","description":"Generates a new API key for the authenticated user (replaces existing key)","tags":["User Management"],"responses":{"200":{"description":"API key generated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"apiKey":{"type":"string","description":"The generated API key (only returned once)"},"message":{"type":"string"}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Get API key status

> Checks if the user has an API key and returns its creation date

```json
{"openapi":"3.0.3","info":{"title":"DeepWriter API","version":"2.0.0"},"tags":[{"name":"User Management","description":"Operations for user authentication and account management"}],"servers":[{"url":"/api","description":"API base path"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"JWT token for user session authentication."}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"A message describing the error"}},"required":["error"]}}},"paths":{"/apiKeyStatus":{"get":{"summary":"Get API key status","description":"Checks if the user has an API key and returns its creation date","tags":["User Management"],"responses":{"200":{"description":"API key status retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"hasApiKey":{"type":"boolean","description":"Whether the user has an API key"},"createdAt":{"type":"string","format":"date-time","description":"When the API key was created (if it exists)","nullable":true}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Submit and validate user API key

> Validates and stores a user's external API key (e.g., OpenRouter)

```json
{"openapi":"3.0.3","info":{"title":"DeepWriter API","version":"2.0.0"},"tags":[{"name":"User Management","description":"Operations for user authentication and account management"}],"servers":[{"url":"/api","description":"API base path"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"JWT token for user session authentication."}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"A message describing the error"}},"required":["error"]}}},"paths":{"/submitApiKey":{"post":{"summary":"Submit and validate user API key","description":"Validates and stores a user's external API key (e.g., OpenRouter)","tags":["User Management"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["apiKey"],"properties":{"apiKey":{"type":"string","description":"The API key to validate and store"}}}}}},"responses":{"200":{"description":"API key validated and stored successfully","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}}}}}},"400":{"description":"Invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```
