Runtime Client API¶
RuntimeClient is the high-level public Python API. Use it when you want the same
resolver, planner, loader, and executor behavior that powers the CLI.
High-level runtime API shared by the CLI and the Python library.
Attributes:
| Name | Type | Description |
|---|---|---|
runtime_loader |
RuntimeLoader
|
Resolver, planner, materialization, and backend-loading boundary. |
runtime_executor |
RuntimeExecutor
|
Prompt execution boundary used once a runtime has been loaded. |
Source code in src/ollm/client.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
resolve
¶
resolve(
model_reference: str, models_dir: Path = Path("models")
) -> ResolvedModel
Resolve a model reference without loading a runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_reference
|
str
|
User-facing model reference such as a built-in alias, Hugging Face repository, or local model path. |
required |
models_dir
|
Path
|
Local models root used for implicit path resolution. |
Path('models')
|
Returns:
| Name | Type | Description |
|---|---|---|
ResolvedModel |
ResolvedModel
|
Normalized model metadata for planning or inspection. |
Source code in src/ollm/client.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
discover_local_models
¶
discover_local_models(
models_dir: Path = Path("models"),
) -> tuple[ResolvedModel, ...]
Discover local materialized models under a models directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models_dir
|
Path
|
Local models root to inspect. |
Path('models')
|
Returns:
| Type | Description |
|---|---|
ResolvedModel
|
tuple[ResolvedModel, ...]: Materialized model directories discovered |
...
|
under the given root. |
Source code in src/ollm/client.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
plan
¶
plan(runtime_config: RuntimeConfig) -> RuntimePlan
Build a runtime plan without loading a backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_config
|
RuntimeConfig
|
Execution configuration to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RuntimePlan |
RuntimePlan
|
Planned backend, specialization, and capability result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the runtime configuration is invalid or no executable plan can be produced. |
Source code in src/ollm/client.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
describe_plan
¶
describe_plan(
runtime_config: RuntimeConfig,
) -> PlanJsonPayload
Return a JSON-serializable inspection payload for a runtime plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_config
|
RuntimeConfig
|
Execution configuration to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PlanJsonPayload |
PlanJsonPayload
|
Serialized inspection payload for CLI or HTTP use. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the runtime configuration is invalid or no executable plan can be produced. |
Source code in src/ollm/client.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
load
¶
load(runtime_config: RuntimeConfig) -> LoadedRuntime
Resolve and load a runtime backend for the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_config
|
RuntimeConfig
|
Execution configuration to load. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
LoadedRuntime |
LoadedRuntime
|
Loaded backend runtime bundle ready for execution. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the model cannot be resolved, materialized, planned, or loaded. |
Source code in src/ollm/client.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
prompt
¶
prompt(
prompt: str,
*,
runtime_config: RuntimeConfig,
generation_config: GenerationConfig | None = None,
system_prompt: str = DEFAULT_SYSTEM_PROMPT,
images: tuple[str, ...] = (),
audio: tuple[str, ...] = (),
sink: StreamSink | None = None,
) -> PromptResponse
Execute one prompt using text plus optional image or audio inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Primary text prompt. |
required |
runtime_config
|
RuntimeConfig
|
Runtime configuration to execute. |
required |
generation_config
|
GenerationConfig | None
|
Optional generation
overrides. Defaults to |
None
|
system_prompt
|
str
|
System instruction prepended to the request when non-empty. |
DEFAULT_SYSTEM_PROMPT
|
images
|
tuple[str, ...]
|
Optional image input paths or URIs. |
()
|
audio
|
tuple[str, ...]
|
Optional audio input paths or URIs. |
()
|
sink
|
StreamSink | None
|
Optional streaming sink for incremental text callbacks. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PromptResponse |
PromptResponse
|
Final prompt response and assistant message payload. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the runtime or generation configuration is invalid or when no executable backend exists. |
Source code in src/ollm/client.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
prompt_parts
¶
prompt_parts(
parts: list[ContentPart],
*,
runtime_config: RuntimeConfig,
generation_config: GenerationConfig | None = None,
system_prompt: str = DEFAULT_SYSTEM_PROMPT,
history: list[Message] | None = None,
sink: StreamSink | None = None,
) -> PromptResponse
Execute a prompt composed from explicit content parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
list[ContentPart]
|
Prompt payload parts in final user-message order. |
required |
runtime_config
|
RuntimeConfig
|
Runtime configuration to execute. |
required |
generation_config
|
GenerationConfig | None
|
Optional generation
overrides. Defaults to |
None
|
system_prompt
|
str
|
System instruction prepended to the request when non-empty. |
DEFAULT_SYSTEM_PROMPT
|
history
|
list[Message] | None
|
Optional prior conversation messages to prepend before the new user message. |
None
|
sink
|
StreamSink | None
|
Optional streaming sink for incremental callbacks. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PromptResponse |
PromptResponse
|
Final prompt response and assistant message payload. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when |
Source code in src/ollm/client.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
session
¶
session(
*,
runtime_config: RuntimeConfig,
generation_config: GenerationConfig | None = None,
session_name: str = "default",
system_prompt: str = DEFAULT_SYSTEM_PROMPT,
messages: list[Message] | None = None,
autosave_path: Path | None = None,
) -> ChatSession
Create a reusable chat session over the shared runtime stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_config
|
RuntimeConfig
|
Runtime configuration for the session. |
required |
generation_config
|
GenerationConfig | None
|
Optional generation
overrides. Defaults to |
None
|
session_name
|
str
|
Human-readable session label. |
'default'
|
system_prompt
|
str
|
Session-wide system instruction. |
DEFAULT_SYSTEM_PROMPT
|
messages
|
list[Message] | None
|
Optional initial transcript messages. |
None
|
autosave_path
|
Path | None
|
Optional transcript autosave path. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ChatSession |
ChatSession
|
Reusable session object bound to the shared runtime |
ChatSession
|
stack. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the runtime or generation configuration is invalid. |
Source code in src/ollm/client.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |