> For the complete documentation index, see [llms.txt](https://docs.netmap.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.netmap.dev/development/adding-api-endpoints.md).

# Adding API Endpoints

Use `get_current_user` or a permission dependency built on it. API-key support is automatic for these dependencies.

Add:

1. Pydantic schema.
2. Router function.
3. Permission dependency.
4. Service logic where needed.
5. Tests.
6. Documentation.

Check `/api/openapi.json` after changes.

## Permission Selection

Use an existing permission when the endpoint fits an existing capability. Add a new permission only when the action cannot be safely represented by the current set.

Examples:

| Endpoint type             | Dependency               |
| ------------------------- | ------------------------ |
| read current user         | `get_current_user`       |
| edit inventory/topology   | `require_topology_write` |
| read security/syslog data | `require_security_view`  |
| passive network tool      | `require_tools_passive`  |
| active network tool       | `require_tools_active`   |
| SuperAdmin setting        | `require_super_admin`    |

## API-Key Support

Do not parse `X-API-Key` inside a route. Use the shared dependencies. `get_current_user` already checks API keys before bearer tokens or cookies.

## Documentation Checklist

Update:

* endpoint inventory;
* API guide examples;
* UI workflow page, if visible in the SPA;
* configuration docs, if new settings are added;
* security docs, if permissions or auth behavior changes.

## Related Pages

* [Backend Development](/development/backend-development.md)
* [API Authentication](/api/authentication.md)
* [Endpoint Reference](/api/endpoint-reference.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.netmap.dev/development/adding-api-endpoints.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
