Backends¶
OpenCode (default)¶
OpenCodeClient(model=None, *, base_url=None, password=None, binary=None, timeout=120)
- Text prompts use the stateless
POST /api/experimental/generate. - Prompts with images open a temporary session with every tool permission denied, attach the images, wait for the reply and delete the session.
- With no
base_url(orOPENCODE_SERVER_URL), it spawnsopencode serveon a free localhost port. Use it as a context manager, or callclose(), to stop the server early. NIRMALA_OPENCODE_BINpoints at a specificopencodeexecutable.
OpenAI-compatible¶
OpenAICompatibleClient(
"openai/gpt-5.6-luna",
base_url="https://openrouter.ai/api", # /v1/chat/completions is appended
api_key=os.environ["OPENROUTER_API_KEY"],
retries=1,
extra_body={"reasoning": {"effort": "high"}},
)
Works with OpenRouter, OpenAI, vLLM, Ollama, LM Studio and anything else that speaks the chat completions API. Useful where a local server cannot run, such as serverless functions.
Your own¶
Implement complete(prompt, *, system, images, model, timeout) -> Completion (and optionally
async acomplete). For tests, use nirmala.testing.FakeLLM([...replies]).