101101
102102
103103class LLM (BaseModel , RetryMixin , NonNativeToolCallingMixin ):
104- """Refactored LLM: simple `completion()`, centralized Telemetry, tiny helpers."""
104+ """Language model interface for OpenHands agents.
105+
106+ The LLM class provides a unified interface for interacting with various
107+ language models through the litellm library. It handles model configuration,
108+ API authentication,
109+ retry logic, and tool calling capabilities.
110+
111+ Example:
112+ >>> from openhands.sdk import LLM
113+ >>> from pydantic import SecretStr
114+ >>> llm = LLM(
115+ ... model="claude-sonnet-4-20250514",
116+ ... api_key=SecretStr("your-api-key"),
117+ ... usage_id="my-agent"
118+ ... )
119+ >>> # Use with agent or conversation
120+ """
105121
106122 # =========================================================================
107123 # Config fields
@@ -388,6 +404,15 @@ def service_id(self, value: str) -> None:
388404
389405 @property
390406 def metrics (self ) -> Metrics :
407+ """Get usage metrics for this LLM instance.
408+
409+ Returns:
410+ Metrics object containing token usage, costs, and other statistics.
411+
412+ Example:
413+ >>> cost = llm.metrics.accumulated_cost
414+ >>> print(f"Total cost: ${cost}")
415+ """
391416 assert self ._metrics is not None , (
392417 "Metrics should be initialized after model validation"
393418 )
@@ -405,9 +430,22 @@ def completion(
405430 add_security_risk_prediction : bool = False ,
406431 ** kwargs ,
407432 ) -> LLMResponse :
408- """Single entry point for LLM completion.
433+ """Generate a completion from the language model.
434+
435+ This is the method for getting responses from the model via Completion API.
436+ It handles message formatting, tool calling, and response processing.
437+
438+ Returns:
439+ LLMResponse containing the model's response and metadata.
440+
441+ Raises:
442+ ValueError: If streaming is requested (not supported).
409443
410- Normalize → (maybe) mock tools → transport → postprocess.
444+ Example:
445+ >>> from openhands.sdk.llm import Message, TextContent
446+ >>> messages = [Message(role="user", content=[TextContent(text="Hello")])]
447+ >>> response = llm.completion(messages)
448+ >>> print(response.content)
411449 """
412450 # Check if streaming is requested
413451 if kwargs .get ("stream" , False ):
0 commit comments