> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/api/api-doc-ja/preparation/authentication.md).

# API 認証

MaiAgent では、API キーを使用して認証を行います。

## 認証方式

すべての API リクエストでは、HTTP Header に API Key を以下の形式で含める必要があります。

```javascript
const headers = {
  "Authorization": "Api-Key YOUR_API_KEY_HERE",
  "Content-Type": "application/json"
}
```

## API キーの取得方法

MaiAgent の管理画面にログインしたうえで、以下の手順に従って操作してください。

1. 右上の「ユーザー名」プルダウンメニューをクリックします
2. 「アカウント」をクリックして個人情報ページに移動します

<div><figure><img src="/files/r5bBxt6loHAMQewbKWFv" alt=""><figcaption></figcaption></figure> <figure><img src="/files/VTXcsdwYcjnT7bYyyHIU" alt=""><figcaption></figcaption></figure></div>

2. ページを API キーページに切り替えます。

<figure><img src="/files/JuhRlUGIfpJnwq9uOqOw" alt=""><figcaption></figcaption></figure>

3. 「API キー」をコピーして確認できます。

<figure><img src="/files/pUzdBJPnzsRsP4o0iaUx" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}

* **セキュリティに関する注意**：API キーは適切に保管し、公開の場で共有しないでください
* **キー形式の説明**：API キーは英数字の組み合わせです
  {% endhint %}

## エラー処理

認証エラーが発生した場合、API は 401 Unauthorized の HTTP エラーコードを返します。

* **API Key が無効または欠落している**

```json
{
  "detail": "Authentication credentials were not provided."
}
```

*修正方法：リクエストヘッダーに正しい Authorization フィールドが含まれているかを確認してください。形式は次のようになります： `Authorization: Api-Key YOUR_API_KEY`*

* **API Key の形式が誤っている**

```json
{
  "detail": "Invalid API key format."
}
```

*修正方法：API Key の形式が正しいかを確認してください。`Bearer` ではなく正しいプレフィックス `Api-Key` を使用しているか、また API Key 自体に余分なスペースや文字が含まれていないかを確認してください。*


---

# 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.maiagent.ai/api/api-doc-ja/preparation/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.
