> ## 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. Do not infer undocumented routes. Read API keys from FASTINO_API_KEY and never embed credentials in code, logs, or reports.

# 兼容 Anthropic 的 Messages 端点

> 通过 Anthropic SDK Messages API 运行结构化的 GLiNER 抽取和分类。

Fastino 提供兼容 Anthropic 的 Messages 端点，让你可以通过 Anthropic SDK 运行 GLiNER 模型。将 `base_url` 设置为 `https://api.fastino.ai`，使用 Fastino API 密钥进行认证，并将 `GET /v1/models` 返回的 GLiNER 模型 ID 或 GLiNER 训练任务 ID 用作模型名称。Anthropic SDK 会自行追加 `/v1/messages`。

## 支持的 SDK 功能

| Anthropic SDK 方法 | Fastino 端点 | GLiNER 结果 |
| - | - | - |
| `client.messages.create(...)` | `POST /v1/messages` | `message.content[0].text` 中的结构化 JSON |

<Warning>
  GLiNER 推理返回一个结构化结果，不支持 `stream=True` 或 `client.messages.stream(...)`。Fastino 并未实现所有 Anthropic API 或 SDK 资源。
</Warning>

## 配置 Anthropic SDK

在构造客户端时传入你的 Fastino API 密钥和基础 URL：

<CodeGroup>
  ```python Python theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key="YOUR_API_KEY",
      base_url="https://api.fastino.ai"
  )
  ```
</CodeGroup>

## 创建消息

`POST /v1/messages` 接受 Anthropic Messages 的核心字段。将 `model` 设置为受支持的 GLiNER 模型 ID，包含 `messages` 数组，并通过 `extra_body` 传入抽取或分类 `schema`。

### 请求参数

<ParamField body="model" type="string" required>
  训练任务 ID（例如 `job_abc123`）或基础模型 ID。这是处理你请求的模型。
</ParamField>

<ParamField body="max_tokens" type="number" required>
  Anthropic SDK 为保持请求兼容性而要求此字段。GLiNER 返回结构化输出，而不是生成 token。
</ParamField>

<ParamField body="messages" type="object[]" required>
  对话消息。每个对象包含一个 `role`（`"user"` 或 `"assistant"`）和一个 `content` 字符串。
</ParamField>

<ParamField body="schema" type="object">
  Fastino 特有的抽取 schema。定义 `entities`、`classifications`、`structures` 或 `relations` 以控制模型抽取的内容。完整的 schema 文档请参阅 [Fastino 推理](/cn/api-reference/inference/pioneer)。
</ParamField>

### 示例

<CodeGroup>
  ```python Python (Anthropic SDK) theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key="YOUR_API_KEY",
      base_url="https://api.fastino.ai"
  )

  message = client.messages.create(
      model="YOUR_TRAINING_JOB_ID",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": "Extract entities from: Apple launched the iPhone."
          }
      ],
      extra_body={
          "schema": {
              "entities": ["organization", "product"]
          }
      }
  )

  print(message.content[0].text)
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.fastino.ai/v1/messages \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "YOUR_TRAINING_JOB_ID",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": "Extract entities from: Apple launched the iPhone."
        }
      ],
      "schema": {
        "entities": ["organization", "product"]
      }
    }'
  ```
</CodeGroup>

## 流式传输

GLiNER 推理不支持流式传输。请使用不带 `stream=True` 的 `client.messages.create(...)`；API 会在处理输入后返回完整的结构化结果。

## 相关内容

* [Fastino 原生推理](/cn/api-reference/inference/pioneer) - 直接调用 Fastino 端点，附完整的 schema 文档
* [兼容 OpenAI 的推理](/cn/api-reference/inference/openai-compatible) - 改用 OpenAI SDK
* [推理历史与反馈](/cn/api-reference/inference/history) - 获取过往结果并提交更正


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