homeblog

How to use Open WebUI with Codex (or ultimately sst/OpenCode)

First go to your running and configured Open WebUI and get your API keys, it's found in: profile picture -> Settings -> Account -> API keys

Now go an create a file here, as described in ~/.codex/config.toml

[model_providers.openwebui]
name = "Open WebUI"
# Make sure you set the appropriate ip for this URL.
base_url = "https://<openwebui-op>/api"
env_key = "OPENWEBUI_API_KEY"

[profiles.test]
model_provider = "openwebui"
model = "qwen3:8b"
#model = "qwen2.5:7b"
#model = "codegemma:7b"

Now you have to set the enviroment variable however you like (you can set it in the same command as in the running of codex)

OPENWEBUI_API_KEY="<API-keys>" codex -p test

All this is sort of documented in here

To run Open WebUI with sst/opencode the process is similar, but you have to configure a few more stuff.

You have to create the infamous opencode.json, it can be set globally in ~/.config/opencode/opencode.json

It has to look like something like this, you have to replace the models with the ones available in your Open WebUI.

{
    "$schema": "https://opencode.ai/config.json",
    "model": "openwebui/qwen2.5:7b",
    "provider": {
        "gepeto": {
            "npm": "@ai-sdk/openai-compatible",
            "name": "openwebui",
            "options": {
                "baseURL": "https://<openwebui-ip>/api"
            },
            "models": {
                "qwen3:8b": {
                    "name": "Qwen3:8b"
                },
                "qwen2.5:7b" : {
                    "name": "Qwen2.5:7b"
                },
                "codegemma:7b": {
                    "name": "CodeGemma:7b"
                }
            }
        }
    }
}

You can get a list querying in /api/models

curl -H "Authorization: Bearer <API-keys>" http://<openwebui-ip>/api/models 

And with jq you can get the correct format for sst/opencode

curl -H "Authorization: Bearer <API-keys>" http://<openwebui-ip>/api/models | jq '.data | map({(.id): {name: .name}}) | add'

All this is sort of documented in here