> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fcontext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 認証

> Financial Context 市場データリクエストを認証する

Financial Context は外部の市場データ呼び出しに対して、2 種類の認証情報を受け付けます。

* Financial Context のアカウント設定で作成した API key
* 承認済みの CLI、MCP、agent クライアント向け OAuth bearer token

API リクエストにはこれらの Financial Context 認証情報を使用します。

## API Key Header

```bash theme={null}
curl "https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US" \
  -H "x-api-key: YOUR_FCONTEXT_API_KEY"
```

`x-api-key` はサーバー間連携で推奨される header です。

## OAuth Bearer Token

```bash theme={null}
curl "https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

Bearer token には `market_data` scope の市場データアクセス権が必要です。

## JavaScript の例

```javascript theme={null}
const response = await fetch("https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US", {
  headers: {
    "x-api-key": process.env.FCONTEXT_API_KEY,
  },
});

if (!response.ok) {
  throw new Error(`Request failed with ${response.status}`);
}

const data = await response.json();
```

## Python の例

```python theme={null}
import os
import requests

response = requests.get(
    "https://openapi.fcontext.com/api/market-data/quote",
    params={"symbols": "AAPL.US"},
    headers={"x-api-key": os.environ["FCONTEXT_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
data = response.json()
```

## エラーレスポンス

| ステータス | 意味                      |
| ----- | ----------------------- |
| `401` | 認証情報がない、期限切れ、または無効      |
| `402` | 有料プランまたは残りのデータリクエスト枠が必要 |
| `403` | 認証情報は有効だが、市場データアクセス権がない |

キーは定期的にローテーションし、使用しなくなったキーは取り消してください。
