llm === .. py:module:: sidequest_bot.lib.llm .. autoapi-nested-parse:: A small client for any OpenAI-compatible chat completions API with tool calling. OpenRouter, OpenAI, Google's OpenAI-compatible Gemini endpoint, Groq and a local Ollama all speak this shape, so the provider and model are just settings. Reasoning models (Claude Haiku 5.5, GPT-6 Luna) think by default and bill thinking as output. ``reasoning`` sets OpenRouter's ``reasoning.effort`` for every request. When a model does think, its ``reasoning_details`` are kept on the assistant message so they go back with the tool results, which Claude needs to carry on after a tool call. .. py:data:: RATE_LIMIT_RETRIES :type: Final :value: 3 .. py:data:: MAX_RETRY_WAIT_SECONDS :type: Final :value: 20.0 .. py:exception:: LLMError Bases: :py:obj:`Exception` The model API failed or answered with something that isn't a chat completion. .. py:class:: ToolCall One tool call the model asked for. ``arguments`` is None when the model sent JSON that doesn't parse. .. py:attribute:: id :type: str .. py:attribute:: name :type: str .. py:attribute:: arguments :type: dict[str, Any] | None .. py:class:: Usage Tokens a request used, and what it cost in USD when the API says (OpenRouter does). .. py:attribute:: input_tokens :type: int :value: 0 .. py:attribute:: output_tokens :type: int :value: 0 .. py:attribute:: cost :type: float | None :value: None .. py:class:: Reply One model turn: ``message`` goes back into the history verbatim; ``text`` and ``tool_calls`` are parsed. .. py:attribute:: message :type: dict[str, Any] .. py:attribute:: text :type: str .. py:attribute:: tool_calls :type: list[ToolCall] .. py:attribute:: usage :type: Usage .. py:class:: ChatClient(base_url: str, api_key: str, model: str, *, reasoning: str | None = None, max_tokens: int = 4000, http: httpx.AsyncClient | None = None) ``POST {base_url}/chat/completions`` with tools. Pass ``http`` to reuse a client (tests pass a mocked one). .. py:attribute:: model .. py:method:: aclose() -> None :async: Close the HTTP client if this instance created it. .. py:method:: complete(messages: list[dict[str, Any]], tools: list[dict[str, Any]] | None = None) -> Reply :async: One model turn over ``messages``, offering ``tools`` if any.