Skip to content

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 (or OPENCODE_SERVER_URL), it spawns opencode serve on a free localhost port. Use it as a context manager, or call close(), to stop the server early.
  • NIRMALA_OPENCODE_BIN points at a specific opencode executable.

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]).