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

# OpenWork

> 通过导入 OpenCode 配置包，将 OpenWork 指向 FlexInference。

OpenWork 驱动 OpenCode 后端，因此您编写的文件是 OpenCode 配置文件。后端会从中读取提供商条目。

OpenWork 在其 UI 中没有设置 `start_within` 的地方，因此截止日期取决于密钥。请先创建一个密钥：参见[代理密钥](/zh/agent-keys)。

## 使用代理进行设置

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

<Accordion title="复制代理设置提示">
  ```text theme={null}
  Configure OpenWork to send its requests to FlexInference. OpenWork drives an OpenCode backend, so the file you write is an OpenCode config file that OpenWork imports into its profile.

  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/` beside my OpenWork checkout and put `opencode.json` in it with this content:

  {
    "$schema": "https://opencode.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,
            "limit": { "context": 400000, "output": 128000 }
          }
        }
      }
    }
  }

  2. Find the OpenCode binary OpenWork should drive and note its path.

  3. Give me the launch command, with the binary path filled in:

  OPENWORK_ELECTRON_USERDATA="$PWD/.openwork-flex-userdata" \
  OPENWORK_DATA_DIR="$PWD/.openwork-flex-data" \
  OPENWORK_DEV_OPENCODE_IMPORT_CONFIG_DIR="$PWD/config" \
  OPENWORK_OPENCODE_BIN=<path to the opencode binary> \
    pnpm dev

  4. Print this line for me to run in that same shell. Do not run it and do not ask for the value:

     export FLEXINFERENCE_API_KEY=<paste your key here>

     OpenWork passes its parent environment to the backend, which is how the value reaches the provider entry.

  5. Add `.openwork-flex-userdata/` and `.openwork-flex-data/` to `.gitignore` if this is a Git repository.

  Rules that matter, do not deviate:
  - OpenWork ignores a config file in the working directory. The bundle only reaches the backend through `OPENWORK_DEV_OPENCODE_IMPORT_CONFIG_DIR`.
  - The import only runs when `OPENWORK_DEV_MODE=1`, which `pnpm dev` sets. A production launch skips it entirely.
  - Reuse the same `OPENWORK_ELECTRON_USERDATA` and `OPENWORK_DATA_DIR` paths on every launch, or you start a fresh profile and lose session history. The copy overwrites on each launch but never deletes.
  - 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 the backend stays on its built-in default.

  Report what you created and give me the exact command to run.
  ```
</Accordion>

## 配置 OpenWork

1. 将 `opencode.json` 放入一个单独的目录中。使用 [OpenCode](/zh/opencode) 中的提供商条目。

2. 在启动 OpenWork 的 shell 中导出密钥。

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

3. 设置导入路径后启动 OpenWork。

   ```bash theme={null}
   OPENWORK_ELECTRON_USERDATA="$PWD/.openwork-flex-userdata" \
   OPENWORK_DATA_DIR="$PWD/.openwork-flex-data" \
   OPENWORK_DEV_OPENCODE_IMPORT_CONFIG_DIR="$PWD/config" \
   OPENWORK_OPENCODE_BIN=/path/to/opencode/binary \
     pnpm dev
   ```

OpenWork 将后端保持在独立的配置文件中，因此它会忽略您工作目录中的配置文件。它会在启动时将指定目录复制到配置文件中，然后使用指向该副本的 `OPENCODE_CONFIG_DIR` 启动后端。

`pnpm dev` 会设置 `OPENWORK_DEV_MODE=1`，这会启用导入功能。

OpenWork 会将父环境传递给后端，因此 `FLEXINFERENCE_API_KEY` 会到达提供商条目。

## 范围来自配置文件，而非文件夹

OpenWork 不会从您的工作目录中读取配置，因此 [OpenCode](/zh/opencode) 提供的全局和按项目划分不适用于此处。范围来自您启动时所针对的配置文件。

| 范围     | 设置方式                                               | 适用于         |
| ------ | -------------------------------------------------- | ----------- |
| 一个配置文件 | `OPENWORK_ELECTRON_USERDATA` 和 `OPENWORK_DATA_DIR` | 该配置文件中的每个会话 |
| 配置包    | `OPENWORK_DEV_OPENCODE_IMPORT_CONFIG_DIR`          | 配置文件导入的任何内容 |

对于您想要切换的每种配置，请保留一对配置文件路径。将相同的配置包导入到两个配置文件中，会为您提供两个独立的设置，每个设置都有自己的会话历史记录。

重复使用上述路径以保留配置文件。更改它们以启动新的配置文件。

## 导入操作在每次启动时复制，从不删除

复制操作在每次启动时运行，并且会覆盖现有文件。编辑配置包，使用相同的 `OPENWORK_ELECTRON_USERDATA` 和 `OPENWORK_DATA_DIR` 路径重新启动，后端将读取新文件。

它从不删除文件。您从配置包中删除的文件会保留在配置文件副本中。清除此文件需要为这两个变量设置新的路径，这将重新启动配置文件并丢失其会话历史记录。仅当残留文件妨碍操作时才这样做。

## 确认密钥已应用

每个响应都带有 `x-flexinference-defaults-applied`。后端和 OpenWork UI 都不显示响应头，因此请改为在仪表板的 **Logs** 下读取请求。

## 故障排除

**导入从未运行。** `OPENWORK_DEV_MODE=1` 是启用它的条件，`pnpm dev` 会设置它。生产环境启动会跳过导入。

**配置编辑未生效。** 复制操作在每次启动时运行，但仅针对给定的配置文件。请使用相同的 `OPENWORK_ELECTRON_USERDATA` 和 `OPENWORK_DATA_DIR` 路径重新启动。

**您删除的文件仍在加载。** 复制操作会覆盖但从不删除。请使用新的路径为这两个变量启动新的配置文件，接受会话历史记录丢失的后果。

**请求从未到达我们。** 配置包中的顶级 `model` 字段是选择提供商的依据。如果没有它，后端将保持其内置默认设置。

**[`401 invalid_api_key`](/zh/errors#invalid_api_key)。** 启动 OpenWork 的 shell 中未设置 `FLEXINFERENCE_API_KEY`。请在该 shell 中导出它，因为后端会继承该 shell 的环境。

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