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

# Authentication

The Duro GraphQL API uses Bearer token and API key (via `x-api-key` header) authentication. All API requests must include an authorization token in the header.

### Which one do you need?

Duro has two authentication mechanisms, and they serve different callers:

| You are…                                                                                   | Use                                                   | Read                                                                  |
| ------------------------------------------------------------------------------------------ | ----------------------------------------------------- | --------------------------------------------------------------------- |
| A script, integration, or backend service acting **as your organization**                  | An **API key** in the `x-api-key` header              | This page                                                             |
| An application signing in **as a human being** — your own UI, a desktop tool, a CAD plugin | The **account APIs**: sign up, sign in, sessions, SSO | [Account Management](/account-management/how-authentication-works.md) |

{% hint style="info" %}
Most integrations want an API key. If you need to authenticate individual people — including single sign-on, password reset, or managing sign-in methods — start with [How Authentication Works](/account-management/how-authentication-works.md).
{% endhint %}

### Obtaining an API Authentication Token

To get started with the Duro API, you'll need to:

1. Create a Duro account at [durohub.com](https://durohub.com)
2. Navigate to your account settings
3. Generate an API token from the Developer section
4. Your URL to get an API key is: `https://durohub.com/org/@<your org slug>/libs/<your library slug>/settings/api-keys`

![API Key Created Window](https://1319565474-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOJejmhbdeb0yjsYB69x4%2Fuploads%2Fgit-blob-ab407478cd18c16a5b67a164d3d2e817fe58322e%2Fapi-key-created-window.png?alt=media)

### Using the Token

Include your API token in all requests using the `x-api-key` header:

```graphql
x-api-key: YOUR_API_TOKEN
```

### Token Security

* Never share your API tokens
* Rotate tokens regularly
* Use different tokens for development and production
* Store tokens securely in environment variables

{% hint style="warning" %}
Never commit API tokens to version control or expose them in client-side code.
{% endhint %}

### Checking the Authenticated User

To confirm a token is valid and inspect the current identity, query `me` under the `user` namespace:

```graphql
query {
  user {
    me {
      hasOrganizations
    }
  }
}
```

`hasOrganizations` is a non-null `Boolean` that returns `true` when the authenticated user belongs to at least one organization. It is useful in onboarding flows to decide whether to prompt the user to create or join an organization before making organization-scoped calls.

A valid token is necessary but not sufficient: `me.permitted` reports whether the identity is allowed to use Duro at all. When it is `false`, every data operation is refused with [`ACCESS_NOT_PERMITTED`](/advanced-topics/error-handling.md#access-errors) until the account is invited or approved — check it before issuing further requests.

See [Current User](/getting-started/current-user.md) for the full set of fields `me` returns.

### Selecting an Organization

Most operations are scoped to a single organization, which you select with the `x-organization` header. It accepts either form:

```http
x-organization: 550e8400-e29b-41d4-a716-446655440000
x-organization: @acme-corp
```

Duro validates the value against the authenticated caller's organization memberships on every request. A UUID or slug you are not a member of is rejected rather than silently falling back to another organization, so the header is safe to drive directly from user input such as an organization picker.

Never rely on a default. When a user belongs to several organizations, their membership list has no defined order, so omitting the header leaves the organization Duro picks for the request unpredictable. This is why [document uploads](/core-concepts/documents.md#organization-context-for-uploads) now take their organization from this header instead of from the uploader's memberships.

Membership records returned with the authenticated user include `organization.slug` alongside the organization's `id`, so you can render a picker and build the header value without a second lookup — prefix the slug with `@` to send the slug form:

```json
{
  "organization": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "slug": "acme-corp"
  }
}
```

### Next Steps

Learn how to make your first API call in the [Hello World](/getting-started/hello-world.md) guide.

To authenticate people rather than services — signup, sign-in, sessions, SSO, and password management — see [Account Management](/account-management/how-authentication-works.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.durohub.com/getting-started/authentication.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.
