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

> ## Agent Instructions
> Use https://docs.fastino.ai/llms.txt to discover and navigate pages. Use https://docs.fastino.ai/llms-full.txt when you need the complete documentation corpus. Use https://docs.fastino.ai/openapi.json as the source of truth for customer-facing routes. For GLiDE decision inference, call POST https://api.fastino.ai/v1/systemone with model fastino/GLiDE. Create managed config jobs with POST /v1/training/jobs using base_model. Both config and interactive jobs use /v1/training/jobs/{job_id} for their canonical REST lifecycle. For custom training loops, use the supported Tinker-compatible SDK client; its /v1/training/compat/tinker adapter is intentionally absent from OpenAPI and must not be called directly. Auto Train is private access and has no public route; direct interested users to sales@fastino.ai. Do not infer undocumented routes. Read API keys from FASTINO_API_KEY and never embed credentials in code, logs, or reports.

# 训练 API 快速入门

> 完成身份验证后选择托管训练或自定义训练循环：准备数据集并选择模型启动训练任务，或由你的应用控制采样、奖励和更新，然后验证规范任务 ID。

本快速入门涵盖训练 API 的两种路径。希望由 Fastino 运行循环时，请使用托管训练。
当你的应用必须控制采样、奖励和模型更新时，请使用自定义训练循环。

## 1. 身份验证

1. 创建 [Fastino 账户](https://agent.fastino.ai/)。
2. 打开 [API 密钥](https://agent.fastino.ai/api-keys)页面。
3. 创建密钥，并在显示时复制。

将密钥存储在环境变量中：

<CodeGroup>
  ```bash macOS/Linux theme={null}
  export FASTINO_API_KEY="fast_sk_..."
  ```

  ```powershell Windows theme={null}
  $env:FASTINO_API_KEY = "fast_sk_..."
  ```
</CodeGroup>

以 `X-API-Key: $FASTINO_API_KEY` 发送此密钥。完整的身份验证契约请参阅
[身份验证](/cn/authentication)。

## 2. 选择路径

| 目标 | 路径 |
| - | - |
| 提供数据和配置，然后由 Fastino 运行训练 | [托管训练](#managed-training) |
| 在你的应用中控制采样、奖励和更新 | [自定义训练循环](#custom-training-loop) |

<span id="managed-training" />

## 托管训练

### 3. 准备数据集

[上传并处理训练数据集](/cn/concepts/datasets)，然后等待其版本变为 `ready`。

### 4. 选择模型

提交前查询实时目录：

```bash theme={null}
curl "https://api.fastino.ai/v1/base-models?supports_training=true" \
  -H "X-API-Key: $FASTINO_API_KEY"
```

保存所选模型的 ID。

### 5. 创建任务

```bash theme={null}
curl -X POST "https://api.fastino.ai/v1/training/jobs" \
  -H "X-API-Key: $FASTINO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "model_name": "my-trained-model",
    "base_model": "MODEL_ID_FROM_CATALOG",
    "datasets": [
      {"name": "my-ready-dataset", "version": "VERSION_NUMBER"}
    ],
    "training_type": "lora"
  }'
```

保存返回的 `id`。它就是所有任务专属路由使用的 `job_id`。仅在重试完全相同的创建请求时复用同一个 `Idempotency-Key`。

### 6. 轮询任务

```bash theme={null}
curl "https://api.fastino.ai/v1/training/jobs/JOB_ID" \
  -H "X-API-Key: $FASTINO_API_KEY"
```

对于配置任务：

* `status` 是持久化的生命周期值，例如 `errored`。
* `normalized_status` 是稳定的轮询值，例如 `failed`。
* `is_terminal_status` 告知客户端何时停止轮询。
* `error_message` 在可用时说明失败原因。

继续轮询，直到 `is_terminal_status` 为 `true`，然后检查最终状态、检查点、日志和部署资格。

<span id="custom-training-loop" />

## 自定义训练循环

自定义训练循环需要团队访问权限以及 Python 3.11 或更高版本。受支持的 SDK 客户端与
Fastino 隐藏的 HTTP 兼容适配器通信。请使用下面的客户端方法，不要自行构造适配器请求。

### 3. 安装经过测试的客户端

<CodeGroup>
  ```bash uv theme={null}
  uv init fastino-training
  cd fastino-training
  uv add "tinker==0.33.1"
  ```

  ```bash pip theme={null}
  mkdir fastino-training && cd fastino-training
  python -m venv .venv
  source .venv/bin/activate
  pip install "tinker==0.33.1"
  ```

  ```powershell pip · Windows theme={null}
  mkdir fastino-training
  cd fastino-training
  py -m venv .venv
  .\.venv\Scripts\Activate.ps1
  pip install "tinker==0.33.1"
  ```
</CodeGroup>

### 4. 配置客户端

每次请求令牌时都会执行 `TINKER_CREDENTIAL_CMD`，该命令必须打印一个非空凭据。

<CodeGroup>
  ```bash macOS/Linux theme={null}
  export TINKER_BASE_URL="https://api.fastino.ai/v1/training/compat/tinker"
  export TINKER_CREDENTIAL_CMD='printf "%s\n" "$FASTINO_API_KEY"'
  ```

  ```powershell Windows theme={null}
  $env:TINKER_BASE_URL = "https://api.fastino.ai/v1/training/compat/tinker"
  $env:TINKER_CREDENTIAL_CMD = 'powershell -NoProfile -Command "[Console]::Out.WriteLine($env:FASTINO_API_KEY)"'
  ```
</CodeGroup>

使用以 `fast_sk_` 开头的普通 Fastino 密钥。以 `tml-` 开头的凭据会被拒绝。
不要设置 `TINKER_API_KEY`。

### 5. 选择已启用的模型

调用 `ServiceClient.get_server_capabilities()`，并从其响应中选择模型和 LoRA 秩：

<CodeGroup>
  ```bash macOS/Linux theme={null}
  export FASTINO_TRAINING_MODEL="<model from capabilities>"
  export FASTINO_TRAINING_LORA_RANK="<supported rank>"
  ```

  ```powershell Windows theme={null}
  $env:FASTINO_TRAINING_MODEL = "<model from capabilities>"
  $env:FASTINO_TRAINING_LORA_RANK = "<supported rank>"
  ```
</CodeGroup>

### 6. 创建任务并采样

创建 `quickstart.py`：

```python theme={null}
import os

import tinker


service_client = tinker.ServiceClient()
outcome = "errored"
try:
    capabilities = service_client.get_server_capabilities()
    print(capabilities)

    training_client = service_client.create_lora_training_client(
        base_model=os.environ["FASTINO_TRAINING_MODEL"],
        rank=int(os.environ["FASTINO_TRAINING_LORA_RANK"]),
    )

    job_id = training_client.get_info().model_data.model_id
    print(f"TRAINING_JOB_ID={job_id}")

    checkpoint = training_client.save_weights_for_sampler(
        "quickstart-sampler"
    ).result()
    sampling_client = service_client.create_sampling_client(
        model_path=checkpoint.path
    )

    tokenizer = sampling_client.get_tokenizer()
    prompt_tokens = tokenizer.apply_chat_template(
        conversation=[
            {
                "role": "user",
                "content": "Explain the purpose of a reward function in one sentence.",
            }
        ],
        add_generation_prompt=True,
        return_dict=False,
    )
    result = sampling_client.sample(
        prompt=tinker.types.ModelInput.from_ints(prompt_tokens),
        num_samples=1,
        sampling_params=tinker.types.SamplingParams(max_tokens=64),
    ).result()

    print(tokenizer.decode(result.sequences[0].tokens))
except KeyboardInterrupt:
    outcome = "interrupted"
    raise
else:
    outcome = "success"
finally:
    service_client.close(outcome).result()
```

运行脚本：

```bash theme={null}
python quickstart.py
```

复制 `TRAINING_JOB_ID=` 后打印的值。

### 7. 验证规范任务

<CodeGroup>
  ```bash macOS/Linux theme={null}
  export TRAINING_JOB_ID="<ID printed by quickstart.py>"
  curl --fail-with-body \
    -H "X-API-Key: $FASTINO_API_KEY" \
    "https://api.fastino.ai/v1/training/jobs/$TRAINING_JOB_ID"
  ```

  ```powershell Windows theme={null}
  $env:TRAINING_JOB_ID = "<ID printed by quickstart.py>"
  Invoke-RestMethod `
    -Headers @{ "X-API-Key" = "$env:FASTINO_API_KEY" } `
    -Uri "https://api.fastino.ai/v1/training/jobs/$env:TRAINING_JOB_ID"
  ```
</CodeGroup>

响应描述的任务与 `create_lora_training_client(...)` 创建的任务相同。继续使用 SDK
客户端执行模型操作，并使用规范任务 API 执行有文档说明的任务读取。

## 继续了解

<CardGroup cols={3}>
  <Card title="数据集" icon="database" href="/cn/concepts/datasets">
    准备并验证训练数据。
  </Card>

  <Card title="任务参考" icon="book" href="/cn/api-reference/training-jobs/create">
    查看完整的请求和响应契约。
  </Card>

  <Card title="训练循环" icon="repeat-2" href="/cn/training/training-loop">
    为自定义循环添加奖励、更新和恢复。
  </Card>
</CardGroup>


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