Skip to content

Model requests

OpenCode asks a model provider for every answer. A harness gives it one provider, and that provider is the harness itself: each request is answered by the AI.Model Layer you provided, in the Durable Object OpenCode runs in.

OpenCodein the Durable Objectharnesssame isolateFastmodel Layerchat completionasks the modeltext and tool callscompletionOpenCodein theDurableObjectharnesssameisolateFastmodelLayerchat completionasks the modeltext and tool callscompletion
OpenCode's request never leaves the isolate as it is. The harness takes it, asks the Fast model through its Layer, and hands the answer back. Only the model Layer's own request, to Workers AI or your gateway, goes out.

OpenCode is given a provider named after the harness (alchemy by default) with the harness’s models, in the OpenAI chat completions format. Its address does not resolve. The harness is the fetch OpenCode uses, so it takes each request for that address and answers it; every other request OpenCode makes goes out unchanged.

OpenCode holds no provider key.

The harness turns the request into an Effect AI prompt and runs it on the AI.Model the prompt chose. That is the Layer you provided: Workers AI, an AI Gateway, or any other provider. The tools OpenCode offered are passed through, and tool calls go back to OpenCode, which runs them.

const reply = yield* harness.session("pr-142").prompt("Fix the failing test.", { model: Smart });

Logging, caching, rate limits and spend caps on your gateway apply to OpenCode’s requests, because they are your runtime’s requests.

Your tools are registered with OpenCode directly. When the model calls one, OpenCode runs the handler in the Durable Object. See Tools.

OpenCode marks a prompt before it runs it, and resumes a marked prompt when it starts again. The harness keeps the object’s alarm armed while a prompt runs, so an evicted object is started again by the alarm and the prompt carries on. See Sessions & prompts.