> ## 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` | 凭证有效，但没有市场数据访问权限 |

请定期轮换密钥，并撤销不再使用的密钥。
