# OpenCode setup

## Compatibility and prerequisites

This guide prepares OpenCode integration with U9 AI. You need an active U9 key, sufficient credit and an available model matching the endpoint. Official documentation was checked on 2026-10-24; this is not an end-to-end test of every client version or upstream model.

## Setup steps

1. Merge the provider entry into your existing opencode.json without replacing other providers.
2. Use @ai-sdk/openai-compatible for Chat Completions. Responses requires a different adapter and separate validation.
3. Set U9AI_API_KEY in the launch environment and replace both model ID placeholders. The file references the environment rather than storing the secret.
4. Select the u9ai model and test short chat, streaming and tools in a temporary project.

## Configuration values

| Setting | Value |
| --- | --- |
| Base URL | https://u9ai.ai/v1 |
| API Key | YOUR_U9AI_API_KEY · U9 API key |
| Model | YOUR_CHAT_MODEL_ID · Available model ID |
| Expected chat endpoint | https://u9ai.ai/v1/chat/completions |

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "u9ai/YOUR_CHAT_MODEL_ID",
  "provider": {
    "u9ai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "U9 AI",
      "options": {
        "baseURL": "https://u9ai.ai/v1",
        "apiKey": "{env:U9AI_API_KEY}"
      },
      "models": {
        "YOUR_CHAT_MODEL_ID": {
          "name": "U9 Chat"
        }
      }
    }
  }
}
```

## Important differences

This is a Chat Completions template; a model name containing codex is not a protocol check. Set context/output limits only from actual specifications.

## Acceptance and handoff

First follow [quickstart](/en/docs/quickstart) to check GET /v1/models without generating content. Then test a short non-streaming request, streaming and any required tool-call round trip separately. Generation tests may incur charges. Record the request ID and verify [cost analysis](/en/docs/billing). For failures, include client version, model ID, endpoint, status and sanitized errors in a [ticket](/en/support). Do not blindly resubmit timed-out jobs.

Give this Markdown file to your developer or agent. Ask it to preserve current settings, substitute only available model IDs and report untested capabilities. Never put real keys in shared Markdown.

## Official reference

[OpenCode](https://opencode.ai/docs/providers/)
