# OpenCode

Configure Laminarity as an OpenAI-compatible OpenCode provider with model discovery, tools, and explicit reasoning variants.

> Verification: contract-tested; checked 2026-09-01; OpenCode 1.18.26 custom provider — The real CLI configuration, model list, streaming, max_tokens output limit, and low reasoning variant pass a local OpenAI-compatible contract test. Production-key certification is tracked separately.

## Store the credential

Run `/connect`, choose `Other`, enter `laminarity` as the provider id, and paste a Laminarity project key. The provider id must match the key used in `opencode.json`.

OpenCode stores connected credentials outside the project. Do not place a real key in `opencode.json` or commit it to source control.

## Configure Laminarity

Use the OpenAI-compatible AI SDK package so OpenCode calls `/v1/chat/completions`. Keep `auto` available for Laminarity routing, and add only concrete model ids returned to your project key by `GET /v1/models`.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "laminarity/auto",
  "provider": {
    "laminarity": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Laminarity",
      "options": {
        "baseURL": "https://api.laminarity.ai/v1"
      },
      "models": {
        "auto": {
          "name": "Laminarity Auto",
          "tool_call": true,
          "limit": { "context": 64000, "output": 16000 }
        },
        "gpt-5.6-sol": {
          "name": "GPT-5.6 Sol via Laminarity",
          "tool_call": true,
          "reasoning": true,
          "variants": {
            "none": { "reasoningEffort": "none" },
            "low": { "reasoningEffort": "low" },
            "medium": { "reasoningEffort": "medium" },
            "high": { "reasoningEffort": "high" },
            "xhigh": { "reasoningEffort": "xhigh" },
            "max": { "reasoningEffort": "max" }
          }
        }
      }
    }
  }
}
```

> Note: The conservative `auto` context setting controls OpenCode history and compaction; it is not a promise that every routed model has the same native context window.

## Discover models before adding them

The list is authenticated and filtered by project policy and price caps. Re-run it before copying a concrete id into the OpenCode model map.

```bash
curl https://api.laminarity.ai/v1/models \
  -H "Authorization: Bearer $LAMINARITY_API_KEY"
```

## Reasoning variants

OpenCode supplies built-in variants for its built-in providers, but a custom provider needs model-specific variants. Define only the effort values advertised for that concrete model by `/v1/models`.

Do not add a reasoning variant to `laminarity/auto`. Automatic requests use Laminarity's model-specific execution profile; a single client-side effort is not portable across every eligible provider.

For GPT-5.6 tool calls, omit reasoning effort or select `none`. Laminarity normalizes legacy `max_tokens` to the modern completion-token field for compatible models.

## Verify the connection

After the basic prompt succeeds, verify a tool-using request and cycle through variants on one concrete reasoning model. A successful `auto` request proves routing connectivity; it does not prove every concrete model is enabled for the key.

```bash
opencode models laminarity
opencode run --model laminarity/auto "Reply with exactly: Laminarity connected"
```

## Java ports built on LangChain4j

If your OpenCode port replaces the AI SDK provider layer with LangChain4j, keep the OpenCode model-selection UI and variant names separate from transport configuration. Map the selected model to `modelName`, map the selected effort to `reasoningEffort`, and use Laminarity's `/v1` base URL and bearer key in the LangChain4j model builder.

Use the LangChain4j guide's runnable Java and Spring Boot configurations as the transport contract. The upstream TypeScript configuration above does not apply verbatim to a Java port.

## Troubleshooting

A missing provider usually means the `/connect` provider id differs from the `provider` key. A missing model means it was not declared in the custom provider map. Refresh `/v1/models` after project-policy changes.

A `400` names an incompatible known parameter. A `401` indicates a missing or invalid key, `402` indicates balance or key-spend limits, `404 model_not_found` indicates an unavailable id, and `429` indicates rate limits.

## Upstream documentation

- [OpenCode custom providers](https://opencode.ai/docs/providers/)
- [OpenCode model variants](https://opencode.ai/docs/models/)
