OpenCode and Kilo Code With Any OpenAI-Compatible Provider: Config Files That Work, and the Context Limit Trap
OpenCode and Kilo Code both let you add your own OpenAI-compatible provider, and both configs look simple. The part that bit me wasn't the URL or the key. It was a missing limit block that made long sessions fall over an hour in, with no obvious cause. Here are the configs I use and the mistakes I made getting there. My examples point at APIClaw , an OpenAI-compatible gateway I build, so weigh…
OpenCode and Kilo Code enable the use of custom OpenAI-compatible providers by allowing users to configure their own provider settings. The common mistakes involve missing or incorrect details such as the limit block, base URL, model ID, and environment variable. The limit block is crucial as it defines the context window and max output tokens for the model.
Without it, long sessions will fail due to the "context limit trap". The base URL should end with /v1, and the key should be stored in an environment variable and referenced as {env:NAME}. The model ID must match the exact ID returned from GET /v1/models. If these details are incorrect, the system will return an invalid API key (401) or model not found (404) error.
Additionally, forgetting to set the limit block in the configuration will result in the client not knowing the context window, causing compaction issues in Kilo Code, and eventually leading to the provider rejecting requests due to being too long.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.