> ## 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.

# Fastino API 上兼容 OpenAI 的推理

> 通过受支持的 OpenAI SDK 方法运行结构化的 GLiNER 抽取和分类。

Fastino 提供兼容 OpenAI 的端点，让你可以通过受支持的 OpenAI SDK 方法运行 GLiNER 模型。将 `base_url` 设置为 `https://api.fastino.ai/v1`，使用 Fastino API 密钥进行认证，并将 `GET /v1/models` 返回的 GLiNER 模型 ID 或 GLiNER 训练任务 ID 作为 `model`。在 Python SDK 中通过 `extra_body` 传入抽取或分类 `schema`，或直接在 JSON 请求体中传入。

<Tip>
  通过更改 `base_url`、API 密钥和模型 ID，并添加 Fastino `schema`，即可复用现有 OpenAI 客户端运行 GLiNER。
</Tip>

## 支持的 SDK 功能

| OpenAI SDK 方法 | Fastino 端点 | GLiNER 结果 |
| - | - | - |
| `client.chat.completions.create(...)` | `POST /v1/chat/completions` | `choices[0].message.content` 中的结构化 JSON |
| `client.responses.create(...)` | `POST /v1/responses` | `response.output_text` 中的结构化 JSON |
| `client.models.list()` | `GET /v1/models` | 可用模型 ID |

<Warning>
  GLiNER 推理返回一个结构化结果，不支持 `stream=True`。Fastino 并未实现所有 OpenAI API 或 SDK 资源；请仅使用上表列出的方法。
</Warning>

## 配置 OpenAI SDK

将 SDK 指向 Fastino 的基础 URL，并提供你的 Fastino API 密钥：

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://api.fastino.ai/v1"
  )
  ```

  ```bash cURL (base URL) theme={null}
  # Set this as the base for all requests
  https://api.fastino.ai/v1
  ```
</CodeGroup>

## Chat completions

`POST /v1/chat/completions` 接受 OpenAI Chat Completions 的核心字段。将受支持的 GLiNER 模型 ID 作为 `model`，并通过 `extra_body` 传入抽取或分类 `schema`。

<CodeGroup>
  ```python Python (OpenAI SDK) theme={null}
  from openai import OpenAI

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

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

  print(response.choices[0].message.content)
  ```

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

## Responses

对于 GLiNER，Responses API 要求将 schema 放在 `text.format.schema`。

<CodeGroup>
  ```python Python (OpenAI SDK) theme={null}
  response = client.responses.create(
      model="YOUR_TRAINING_JOB_ID",
      input="Extract entities from: Apple launched the iPhone.",
      max_output_tokens=128,
      extra_body={
          "text": {
              "format": {
                  "schema": {
                      "entities": ["organization", "product"]
                  }
              }
          }
      }
  )

  print(response.output_text)
  ```
</CodeGroup>

## 列出可用模型

使用 `GET /v1/models` 获取可用于这些端点的模型列表。

<CodeGroup>
  ```python Python (OpenAI SDK) theme={null}
  models = client.models.list()
  for model in models.data:
      print(model.id)
  ```

  ```bash cURL theme={null}
  curl https://api.fastino.ai/v1/models \
    -H "X-API-Key: YOUR_API_KEY"
  ```
</CodeGroup>

## 流式传输

GLiNER 推理不支持流式传输。请勿设置 `stream=True`；API 会在处理输入后返回完整的结构化结果。

## 传入 Fastino 特有的字段

对于 Chat Completions，请通过 `extra_body={"schema": ...}` 传入 `schema`。对于 Responses，请通过 `extra_body={"text": {"format": {"schema": ...}}}` 传入。原始 HTTP 请求使用相同的端点特定结构。

## 相关内容

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


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