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

# 快速入门

> 进行你的第一个 Olostep 请求：获取一个 API 密钥，抓取一个页面，并阅读结果。

抓取一个网页并将其内容获取为 Markdown。一次抓取会使用你账户中的[积分](https://docs.olostep.com/features/scrapes.md#pricing)。

**1. 获取你的 API 密钥**

登录到 [Olostep 控制面板](https://www.olostep.com/dashboard/api-keys)并复制一个 API 密钥。如果你没有账户，[创建一个](https://www.olostep.com/auth/)。

将密钥设置为环境变量。这样密钥就不会出现在你的代码中。

```bash macOS / Linux theme={null}
export OLOSTEP_API_KEY="<YOUR_API_KEY>"
```

```powershell Windows (PowerShell) theme={null}
$env:OLOSTEP_API_KEY = "<YOUR_API_KEY>"
```

**2. 检查你的密钥**

获取你的积分余额。此请求会检查密钥，并且是免费的。

```bash macOS / Linux theme={null}
curl --max-time 30 "https://api.olostep.com/user/credits/info" \
  -H "Authorization: Bearer $OLOSTEP_API_KEY"
```

```powershell Windows (PowerShell) theme={null}
Invoke-RestMethod -Uri "https://api.olostep.com/user/credits/info" `
  -Headers @{ Authorization = "Bearer $env:OLOSTEP_API_KEY" } -TimeoutSec 30
```

如果密钥有效，响应会显示你的积分余额。新账户初始包含 500 积分。cURL 响应如下（已缩短）：

```json Response (shortened) theme={null}
{
  "credits": 500,
  "allow_usage": true
}
```

如果你收到 `401` 或 `402`，请参阅[如果不起作用](#if-it-does-not-work)。

**3. 安装客户端**

安装你想使用的客户端。对于 cURL 或 PowerShell，跳过此步骤。

```bash Python theme={null}
pip install olostep
```

```bash Node theme={null}
npm install olostep
```

```bash CLI theme={null}
curl -fsSL https://cli.olostep.com | sh
```

Python SDK 需要 Python 3.11 到 3.13。Node.js SDK 需要 Node.js 18 或更高版本。CLI 需要 macOS 或 Linux 以及 Node.js 20.19 或更高版本。详情请参阅[安装 CLI](https://docs.olostep.com/cli/install.md)。

CLI 使用你的 Olostep 账户登录，而不是 API 密钥。如果安装程序更改了你的 `PATH`，请先打开一个新的终端。然后登录：

```bash theme={null}
olostep login
```

**4. 抓取一个页面**

将 `https://example.com` 发送到抓取端点并请求 Markdown。使用你设置密钥的同一个终端。

```bash cURL theme={null}
curl --max-time 180 -X POST "https://api.olostep.com/v1/scrapes" \
  -H "Authorization: Bearer $OLOSTEP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url_to_scrape": "https://example.com", "formats": ["markdown"]}'
```

```powershell PowerShell theme={null}
$body = @{ url_to_scrape = "https://example.com"; formats = @("markdown") } | ConvertTo-Json
$response = Invoke-RestMethod -Method Post -Uri "https://api.olostep.com/v1/scrapes" `
  -Headers @{ Authorization = "Bearer $env:OLOSTEP_API_KEY" } `
  -ContentType "application/json" -Body $body -TimeoutSec 180
$response.result.markdown_content
```

```python Python theme={null}
from olostep import Olostep

client = Olostep()  # Reads the OLOSTEP_API_KEY environment variable
result = client.scrapes.create(
    url_to_scrape="https://example.com", formats=["markdown"]
)
print(result.markdown_content)
```

```js Node theme={null}
import Olostep from 'olostep'

const client = new Olostep({ apiKey: process.env.OLOSTEP_API_KEY })
const result = await client.scrapes.create({ url: 'https://example.com', formats: ['markdown'] })
console.log(result.markdown_content)
```

```bash CLI theme={null}
olostep scrape https://example.com -f markdown
```

要运行 Python 示例，将其保存为 `quickstart.py` 并运行 `python quickstart.py`。要运行 Node.js 示例，将其保存为 `quickstart.mjs` 并运行 `node quickstart.mjs`。

**5. 阅读结果**

cURL 打印原始 JSON 响应。PowerShell、Python 和 Node.js 打印 Markdown 内容。CLI 打印适合你终端的结果。

在 API 响应中，页面内容位于 `result.markdown_content` 中：

```json API response (shortened) theme={null}
{
  "id": "scrape_abc123",
  "object": "scrape",
  "created": 1763049600,
  "url": "https://example.com",
  "retrieve_id": "abc123",
  "result": {
    "markdown_content": "# Example Domain\n\nThis domain is for use in illustrative examples in documents..."
  }
}
```

如果你想稍后再次获取此抓取，请保留 `id`，使用 [`GET /v1/scrapes/{scrape_id}`](https://docs.olostep.com/api-reference/scrapes/get)。

## 如果不起作用

使用 cURL 时，添加 `-i` 到命令以查看 HTTP 状态。

| 你看到的 | 这意味着什么 | 该怎么办 |
| - | - | - |
| `401` 或 `402`。在 Python 中：`OlostepServerError_AuthFailed` 或 `OlostepServerError_CreditsExhausted`。 | API 密钥缺失或无效，或者你的账户没有剩余积分。 | 确保在同一个终端中设置了 `OLOSTEP_API_KEY`，并且密钥正确。然后在[控制面板](https://www.olostep.com/dashboard/)中检查你的积分。要检查密钥和余额，请运行步骤 2 中的检查。 |
| `400` | 请求无效，或 Olostep 无法访问该 URL。响应主体会说明原因。 | 阅读响应主体。检查 URL 和请求字段。 |
| `504`。在 Python 中：`OlostepServerError_NoResultInResponse`。 | 抓取未能及时完成。默认情况下，两个 SDK 都会重新发送请求，因此 SDK 调用可能需要几分钟才会失败。 | 重新发送请求，或尝试另一个 URL。失败的抓取不消耗积分。 |
| `429` | 你发送了太多请求。 | 等待，然后重新发送请求。如果响应有 `Retry-After` 头，请等待该秒数。 |
| Python：`ValueError: API key is required when using the real HTTP transport` | SDK 未找到 API 密钥。 | 在启动 Python 之前设置 `OLOSTEP_API_KEY`，或将 `api_key` 传递给 `Olostep()`。 |
| Python 1.2.3：关于 `extra field(s)` 的 `UserWarning` | 响应包含此 SDK 版本未定义的字段。 | 如果示例打印 Markdown，继续即可。你可以忽略此警告。 |

## 下一步

> [card] [抓取选项](https://docs.olostep.com/features/scrapes.md)
>
> 格式、解析器、结构化 JSON 等。

> [card] [一次抓取多个 URL](https://docs.olostep.com/features/batches.md)
>
> 在一个批处理作业中抓取 URL 列表。

> [card] [抓取一个网站](https://docs.olostep.com/features/crawls.md)
>
> 获取整个网站的页面。

> [card] [搜索网络](https://docs.olostep.com/features/search.md)
>
> 为查询找到相关链接。

> [card] [答案](https://docs.olostep.com/features/answers.md)
>
> 提出问题并获得带有来源的答案。

> [card] [SDKs](https://docs.olostep.com/sdks/overview.md)
>
> Python 和 Node.js 库。

> [card] [AI 代理](https://docs.olostep.com/integrations/mcp-server.md)
>
> 使用 Olostep MCP 服务器为你的 AI 代理提供网络访问。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.