> For the complete documentation index, see [llms.txt](https://docs.deepwriter.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.deepwriter.com/api-access/user-management.md).

# 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"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.deepwriter.com/api-access/user-management.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
