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

# 快速开始

> 用 AGICTO API 发起第一次 OpenAI 兼容格式调用

本页帮你用 OpenAI 兼容格式发出第一条 AGICTO API 请求。完成后，你会知道 API Key 放在哪里、Base URL 怎么写，以及如何验证响应是否成功。

## 前置条件

* 你已经有 AGICTO API 的 API Key
* 你的账户有可用余额或额度
* 你的运行环境可以访问 AGICTO API

<Info>
  如果你只是想快速验证连通性，先使用 Chat completions。它最适合作为第一次调用。
</Info>

## 1. 设置 API Key

调用接口时，将 API Key 放在 `Authorization` Header 中。

```http theme={null}
Authorization: Bearer $API_KEY
```

<Tip>
  不要在客户端代码、公开仓库或日志中暴露 API Key。
</Tip>

## 2. 使用 Base URL

AGICTO API 的 Base URL 是：

```text theme={null}
https://api.agicto.cn/v1/
```

直接复制控制台里显示的 Base URL。示例请求会使用完整地址。

本页使用 Chat completions，完整请求地址是：

```text theme={null}
https://api.agicto.cn/v1/chat/completions
```

## 3. 发送第一条 Chat 请求

复制下面的命令，将 `$API_KEY` 替换为你的 API Key，将 `model` 替换为你账户可用的模型名。

```bash theme={null}
curl https://api.agicto.cn/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "你好，请用一句话介绍 AGICTO API。"
      }
    ]
  }'
```

成功时，接口会返回模型生成的消息。失败时，先检查 API Key、余额、模型名和请求 JSON。

## 4. 使用 OpenAI SDK

如果你已经在项目中使用 OpenAI SDK，可以把客户端的 Base URL 改为控制台显示的 Base URL。

<CodeGroup>
  ```js Node.js theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.AGICTO_API_KEY,
    baseURL: "https://api.agicto.cn/v1/"
  });

  const completion = await client.chat.completions.create({
    model: "gpt-4o",
    messages: [
      {
        role: "user",
        content: "你好，请用一句话介绍 AGICTO API。"
      }
    ]
  });

  console.log(completion.choices[0].message.content);
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["AGICTO_API_KEY"],
      base_url="https://api.agicto.cn/v1/",
  )

  completion = client.chat.completions.create(
      model="gpt-4o",
      messages=[
          {
              "role": "user",
              "content": "你好，请用一句话介绍 AGICTO API。",
          }
      ],
  )

  print(completion.choices[0].message.content)
  ```
</CodeGroup>

## 5. 下一步

<CardGroup cols={2}>
  <Card title="模型与价格" icon="boxes-stacked" href="/guides/models">
    查看模型类型、价格字段和模型名复制方式。
  </Card>

  <Card title="OpenAI 兼容格式" icon="code" href="/guides/openai-compatible">
    查看聊天、嵌入、图片和视频的迁移方式。
  </Card>

  <Card title="账户余额" icon="wallet" href="/api-reference/account/balance">
    调用余额接口，确认账户可用额度。
  </Card>

  <Card title="API reference" icon="book-open" href="/api-reference/introduction">
    查看完整接口列表和 Apifox 同步示例。
  </Card>

  <Card title="流式输出" icon="bars-staggered" href="/guides/streaming">
    让聊天应用边生成边显示。
  </Card>

  <Card title="故障排查" icon="circle-question" href="/guides/troubleshooting">
    按错误现象定位 API Key、余额、限速和模型问题。
  </Card>
</CardGroup>
