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

# OpenScience

> 仅通过配置将 OpenScience 指向 FlexInference。

OpenScience 从 JSON 文件中读取提供商条目。标准构建无需更改源代码。

OpenScience 可以在配置中设置 `start_within`，因此此处代理密钥是可选的。密钥仍然是更简单的路径，因为它无需重启即可更改。请参阅[代理密钥](/zh/agent-keys)。

## 使用代理进行设置

打开下面的代码块并将其复制到任何编码代理中。提示绝不会要求您的 API 密钥：代理会配置所有其他内容，然后打印出您需要自行运行的导出命令。

<Accordion title="复制代理设置提示">
  ```text theme={null}
  Configure OpenScience to send its requests to FlexInference. This is config only: no source change, no fork, no patch.

  You will never see or handle my API key. The provider entry stores only the `{env:FLEXINFERENCE_API_KEY}` template, and I export the value myself. Do not ask me for the key, and do not read it from my environment.

  1. Create a directory named `config/` and put `openscience.json` in it with this content:

  {
    "$schema": "https://syntheticsciences.ai/config.json",
    "model": "flexinference/gpt-5.6-sol",
    "provider": {
      "flexinference": {
        "name": "FlexInference",
        "env": ["FLEXINFERENCE_API_KEY"],
        "npm": "@ai-sdk/openai-compatible",
        "options": {
          "apiKey": "{env:FLEXINFERENCE_API_KEY}",
          "baseURL": "https://api.flexinference.com/v1"
        },
        "models": {
          "gpt-5.6-sol": {
            "name": "GPT-5.6 Sol",
            "reasoning": true,
            "tool_call": true
          }
        }
      }
    }
  }

  2. Print these lines for me to run. Do not run the export and do not ask for the value:

  export FLEXINFERENCE_API_KEY=<paste your key here>
  OPENSCIENCE_CONFIG_DIR=./config bun run dev

  3. Add `config/package.json`, `config/bun.lock`, and `config/node_modules/` to `.gitignore`. OpenScience writes those into any directory it loads config from on first run.

  Rules that matter, do not deviate:
  - Use `OPENSCIENCE_CONFIG_DIR`, not `OPENSCIENCE_CONFIG`. The first names a directory and scans it for commands, agents, and plugins. The second names a single file and scans nothing.
  - If I ask for a plugin, place the file at `config/plugins/<name>.js` and leave the `plugin` key out of the JSON entirely.
  - Tell me that any `.openscience` or `.synsc` directory inside a repository I open is also scanned for plugins, and that those plugins run with my exported key in the environment. Recommend I export the key only in the launch shell. Every entry in that array without a `file://` prefix is treated as an npm package name and handed to `bun add`, which fails and takes plugin startup down. The directory scan is one level deep and loads every `.js` and `.ts` sitting directly in `plugins/`, so keep shared modules outside it.
  - Do NOT put `start_within` in any model's `options`. FlexInference injects a key default only when the field is ABSENT, so writing it here permanently overrides my agent key's deadline with whatever you hardcoded. Only add it if I tell you I am not using an agent key.
  - Keep `options.apiKey` as the literal `{env:FLEXINFERENCE_API_KEY}` template. Never inline my key.
  - The top-level `model` field is what selects the provider. Without it OpenScience stays on its built-in default.
  - Every key under `models` is a slug sent verbatim on the wire, so it must be one FlexInference serves.

  Verify the file is valid JSON, then report what you created and the exact command to run.
  ```
</Accordion>

## 配置 OpenScience

1. 在启动 OpenScience 的 shell 中导出密钥。

   ```bash theme={null}
   export FLEXINFERENCE_API_KEY=flex_live_...
   ```

2. 将提供商条目写入 `openscience.json`。

   ```json theme={null}
   {
     "$schema": "https://syntheticsciences.ai/config.json",
     "model": "flexinference/gpt-5.6-sol",
     "provider": {
       "flexinference": {
         "name": "FlexInference",
         "env": ["FLEXINFERENCE_API_KEY"],
         "npm": "@ai-sdk/openai-compatible",
         "options": {
           "apiKey": "{env:FLEXINFERENCE_API_KEY}",
           "baseURL": "https://api.flexinference.com/v1"
         },
         "models": {
           "gpt-5.6-sol": {
             "name": "GPT-5.6 Sol",
             "reasoning": true,
             "tool_call": true
           }
         }
       }
     }
   }
   ```

3. 设置配置目录后启动 OpenScience。

   ```bash theme={null}
   OPENSCIENCE_CONFIG_DIR=/path/to/config bun run dev
   ```

当您的密钥包含截止日期时，请将 `start_within` 排除在 `options` 之外。我们仅在字段缺失时才填充存储的默认值，因此此处的值将覆盖每个请求中的密钥。

当您**不**使用代理密钥时，请在每个模型上设置 `"start_within": "default"`。这是安全的基线，因为在没有会话选择的情况下选择的模型将路由标准请求，而不是意外地进行竞速。

## 文件存放位置

OpenScience 会合并来自多个位置的配置，后来的来源会覆盖之前的。

* OpenScience 配置目录中的全局用户配置。
* `OPENSCIENCE_CONFIG`，一个配置文件的路径。
* 在向上遍历到工作树根目录时找到的 `synsc.jsonc`、`synsc.json`、`openscience.jsonc` 和 `openscience.json`，除非设置了 `OPENSCIENCE_DISABLE_PROJECT_CONFIG`。
* `OPENSCIENCE_CONFIG_CONTENT`，包含内联 JSON。
* 在该遍历过程中，每个 `.openscience` 或 `.synsc` 目录中的相同四个名称，以及由 `OPENSCIENCE_CONFIG_DIR` 指定的任何目录。

这两个路径变量不可互换。`OPENSCIENCE_CONFIG` 指定一个文件。`OPENSCIENCE_CONFIG_DIR` 指定一个目录，并将其整体视为配置，扫描其中的命令、代理和插件。当捆绑包包含 JSON 以外的内容时，请使用目录形式。

## 通过放置文件加载插件

OpenScience 会扫描每个配置目录以查找 `{plugin,plugins}/*.{ts,js}`，并将其找到的文件作为本地文件加载。将文件放在 `plugins/flex.js`，并从 JSON 中省略 `plugin`。

```
config/
  openscience.json
  plugins/
    flex.js
```

将路径写入 `plugin` 是无效的。OpenScience 会将其中没有 `file://` 前缀的每个条目视为 npm 包名并传递给 `bun add`，因此 `"./plugins/flex.js"` 将无法安装并导致插件启动失败。

扫描深度为一层，它会加载直接位于 `plugins/` 中的所有 `.js` 和 `.ts` 文件。请将共享模块放在该目录之外，否则 OpenScience 也会将它们作为插件加载。

OpenScience 首次从目录加载配置时，会向其中写入 `package.json`、`bun.lock`、`node_modules/` 以及一个包含它们的 `.gitignore` 文件。请注意这些文件，并将其排除在 Git 之外。

## 确认密钥已应用

每个响应都附带 `x-flexinference-defaults-applied`。OpenScience 不会在工作区中显示响应头，因此请改为在仪表板的**日志**下查看请求。

## 故障排除

**插件未加载。** 在 `plugin` 中命名它会将其作为包名发送给 `bun add`，这会导致失败并使插件启动中断。请将文件放在配置目录内的 `plugins/flex.js`，并从 JSON 中省略 `plugin`。

**辅助模块被加载为插件。** 扫描会加载直接位于 `plugins/` 中的所有 `.js` 和 `.ts` 文件。请将共享模块移到该目录之外。

**请求从未到达我们。** 顶层 `model` 字段用于选择提供商。如果没有它，OpenScience 将保持其内置默认值。

**[`401 invalid_api_key`](/zh/errors#invalid_api_key)。** 启动 OpenScience 的 shell 中未设置 `FLEXINFERENCE_API_KEY`。请在启动前导出它。

**[`400 flex_unsupported_for_anthropic`](/zh/errors#flex_unsupported_for_anthropic)。** `options` 中的持续时间到达了您自己的 Anthropic 密钥上的 `claude-*` 模型。Claude 持续时间运行的[竞速](/zh/deadline-routing)需要托管密钥。请移除持续时间，让密钥携带截止日期。

**密钥的截止日期从未应用。** 模型 `options` 中的 `start_within` 优先于密钥，因为我们仅在字段缺失时才填充存储的默认值。请从条目中移除它。

有关我们返回的所有拒绝信息，请参阅[错误](/zh/errors)；有关非 OpenScience 特有的错误，请参阅[代理密钥](/zh/agent-keys)；有关 OpenScience 共享的每个模型和每个变体的截止日期选项，请参阅 [OpenCode](/zh/opencode)。
