> ## 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 為外部市場資料呼叫支援兩類憑證：

* 在 Financial Context 帳戶設定中建立的 API key
* 面向已核准 CLI、MCP 或 agent 用戶端的 OAuth bearer token

請使用這些 Financial Context 憑證發起 API 請求。

## 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` | 憑證有效，但沒有市場資料存取權限 |

請定期輪換金鑰，並撤銷不再使用的金鑰。
