> For the complete documentation index, see [llms.txt](https://guides.ia.numerique.gouv.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guides.ia.numerique.gouv.fr/albert-api/prise-en-main/authentication.md).

# Authentification

Albert API utilise le schéma de sécurité **HTTPBearer** : chaque requête authentifiée doit inclure un jeton dans l’en-tête `Authorization`.

## Obtenir un jeton

Les jetons d’API sont créés via l’endpoint `POST /v1/me/keys`. La procédure détaillée (création, liste, révocation) est décrite dans [Clés API](/albert-api/compte-and-usage/api-keys.md).

## Format de l’en-tête

```
Authorization: Bearer <votre_jeton>
```

Ne commitez jamais de jeton dans un dépôt Git ; utilisez des variables d’environnement ou un gestionnaire de secrets.

## Exemples (curl / Python / JavaScript)

Remplacez `VOTRE_JETON` et, si besoin, l’identifiant de modèle par des valeurs valides pour votre compte.

Le SDK officiel `openai` accepte une URL de base personnalisée. Le paramètre `api_key` sert a transporter **votre jeton Albert** (ce n’est pas une clé du fournisseur OpenAI).

{% tabs %}
{% tab title="curl" %}

```bash
curl -sS "https://albert.api.etalab.gouv.fr/v1/models" \
  -H "Authorization: Bearer VOTRE_JETON" \
  -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="Python" %}

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://albert.api.etalab.gouv.fr/v1",
    api_key=os.environ["ALBERT_API_KEY"],
)

models = client.models.list()
print([m.id for m in models.data])
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://albert.api.etalab.gouv.fr/v1",
  apiKey: process.env.ALBERT_API_KEY,
});

const models = await client.models.list();
console.log(models.data.map((m) => m.id));
```

{% endtab %}
{% endtabs %}

La clé publique reçue à la création d’une clé API Albert se place dans `ALBERT_API_KEY`. Toutes les routes documentées sous `/v1/...` sont alors accessibles avec le même mécanisme que pour l’API OpenAI.


---

# 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://guides.ia.numerique.gouv.fr/albert-api/prise-en-main/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.
