API Reference¶
Quick reference for the current public API.
For provider-level feature differences, see Provider Capabilities.
Which Entry Point?¶
| If you want to... | Use | Learn the workflow in... |
|---|---|---|
| Ask one prompt about one source (or no source) | run() |
Sending Content to Models |
| Ask many prompts against shared sources | run_many() |
Analyzing Collections with Source Patterns |
| Submit non-urgent work and collect it later | defer() / defer_many() |
Building With Deferred Delivery |
| Check deferred job status or collect terminal results | inspect_deferred() / collect_deferred() / cancel_deferred() |
Submitting Work for Later Collection |
| Feed tool results back into a conversation turn | continue_tool() |
Building an Agent Loop |
| Reuse Gemini context across later calls | create_cache() |
Reducing Costs with Context Caching |
Entry Points¶
The primary execution functions are exported from pollux:
Run a single prompt, optionally with a source for context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str | None
|
The prompt to run. |
None
|
source
|
Source | None
|
Optional source for context (file, text, URL). |
None
|
config
|
Config
|
Configuration specifying provider and model. |
required |
options
|
Options | None
|
Optional additive features such as schema or reasoning controls. |
None
|
Returns:
| Type | Description |
|---|---|
ResultEnvelope
|
ResultEnvelope with answers and metrics. |
Example
config = Config(provider="gemini", model="gemini-2.0-flash") result = await run("Summarize this document", source=Source.from_file("doc.pdf"), config=config) first_answer = next(iter(result["answers"]), "") print(first_answer)
Source code in src/pollux/__init__.py
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 | |
Run multiple prompts with shared sources for source-pattern execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts
|
str | Sequence[str | None] | None
|
One or more prompts to run. |
None
|
sources
|
Sequence[Source]
|
Optional sources for shared context. |
()
|
config
|
Config
|
Configuration specifying provider and model. |
required |
options
|
Options | None
|
Optional additive features such as schema or reasoning controls. |
None
|
Returns:
| Type | Description |
|---|---|
ResultEnvelope
|
ResultEnvelope with answers (one per prompt) and metrics. |
Example
config = Config(provider="gemini", model="gemini-2.0-flash") result = await run_many( ["Question 1?", "Question 2?"], sources=[Source.from_text("Context...")], config=config, ) for answer in result["answers"]: print(answer)
Source code in src/pollux/__init__.py
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 | |
Submit a single deferred request and return a serializable handle.
Source code in src/pollux/__init__.py
97 98 99 100 101 102 103 104 105 106 | |
Submit deferred work and return a handle for later inspection/collection.
Source code in src/pollux/__init__.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
Inspect the current state of a deferred job.
Source code in src/pollux/__init__.py
172 173 174 175 176 177 178 179 180 | |
Collect a terminal deferred job into the standard ResultEnvelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
DeferredHandle
|
The deferred handle returned by |
required |
response_schema
|
type[Any] | dict[str, Any] | None
|
Optional Pydantic model or JSON Schema for structured output rehydration. Must match the schema used at submission time. |
None
|
Source code in src/pollux/__init__.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
Request provider-side cancellation for a deferred job.
Source code in src/pollux/__init__.py
206 207 208 209 210 211 212 213 214 | |
Continue a conversation with the results of tool calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
continue_from
|
ResultEnvelope
|
The previous ResultEnvelope containing tool calls. |
required |
tool_results
|
list[dict[str, Any]]
|
List of tool results as dicts (must provide 'role': 'tool', 'tool_call_id', and 'content'). |
required |
config
|
Config
|
Configuration specifying provider and model. |
required |
options
|
Options | None
|
Optional additive features. |
None
|
Returns:
| Type | Description |
|---|---|
ResultEnvelope
|
ResultEnvelope with the model's next response. |
Source code in src/pollux/__init__.py
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 | |
Create a persistent context cache for use with run() / run_many().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
Sequence[Source]
|
Content to cache (files, text, URLs). |
required |
config
|
Config
|
Configuration specifying provider and model. |
required |
system_instruction
|
str | None
|
Optional system-level instruction baked into the cache. |
None
|
tools
|
list[dict[str, Any]] | list[Any] | None
|
Optional tools to bake into the cache. |
None
|
ttl_seconds
|
int
|
Time-to-live in seconds (must be ≥ 1). |
3600
|
Returns:
| Type | Description |
|---|---|
CacheHandle
|
A |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If the provider does not support persistent caching or ttl_seconds is invalid. |
Example
cfg = Config(provider="gemini", model="gemini-2.5-flash") handle = await create_cache( [Source.from_file("book.pdf")], config=cfg, ttl_seconds=3600, ) result = await run("Summarize.", config=cfg, options=Options(cache=handle))
Source code in src/pollux/__init__.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
Core Types¶
Source includes both the generic source constructors and narrow
provider-specific helpers such as Source.with_gemini_video_settings(...).
A structured representation of a single input source.
Source code in src/pollux/source.py
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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
Functions¶
from_text
classmethod
¶
from_text(text, *, identifier=None)
Create a Source from text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text content. |
required |
identifier
|
str | None
|
Display label. Defaults to the first 50 characters of text. |
None
|
Source code in src/pollux/source.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
from_json
classmethod
¶
from_json(data, *, identifier=None)
Create a Source from a JSON-serializable object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any] | Any
|
A dictionary or object to serialize into a JSON string. If the object
has a |
required |
identifier
|
str | None
|
Display label. Defaults to "json-data". |
None
|
Source code in src/pollux/source.py
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 | |
from_file
classmethod
¶
from_file(path, *, mime_type=None)
Create a Source from a local file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the file. Must exist or |
required |
mime_type
|
str | None
|
MIME type override. Auto-detected from extension when None. |
None
|
Source code in src/pollux/source.py
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 | |
from_youtube
classmethod
¶
from_youtube(url)
Create a Source from a YouTube URL reference (no download).
Source code in src/pollux/source.py
121 122 123 124 125 126 127 128 129 130 131 | |
from_uri
classmethod
¶
from_uri(uri, *, mime_type='application/octet-stream')
Create a Source from a URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Remote URI (e.g. |
required |
mime_type
|
str
|
MIME type. Defaults to |
'application/octet-stream'
|
Source code in src/pollux/source.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
from_arxiv
classmethod
¶
from_arxiv(ref)
Create an arXiv PDF Source from an arXiv ID or URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str
|
An arXiv ID (e.g. |
required |
Source code in src/pollux/source.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
gemini_video_settings_for ¶
gemini_video_settings_for(provider)
Return Gemini video settings when the active provider can use them.
Source code in src/pollux/source.py
207 208 209 210 211 212 213 214 | |
provider_hints_for ¶
provider_hints_for(provider)
Return immutable provider hints as plain dictionaries for transport.
Source code in src/pollux/source.py
216 217 218 219 220 221 222 223 224 225 226 227 228 | |
cache_identity_hash ¶
cache_identity_hash(*, provider=None)
Compute SHA256 hash for cache identity.
Includes provider-visible source semantics such as Gemini video settings. Falls back to raw content hash when no provider-specific settings apply, preserving backward-compatible cache keys.
Source code in src/pollux/source.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
with_gemini_video_settings ¶
with_gemini_video_settings(
*, start_offset=None, end_offset=None, fps=None
)
Return a copy with validated Gemini video controls attached.
Pollux keeps this API provider-specific and stable even if Google's underlying wire fields evolve. The Gemini adapter maps these settings to the current SDK request shape. These settings only affect Gemini requests and Gemini explicit-cache identity.
Source code in src/pollux/source.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
Opaque handle returned by create_cache().
Pass instances via Options(cache=handle) to reuse a persistent
context cache across run() / run_many() calls.
Source code in src/pollux/cache.py
27 28 29 30 31 32 33 34 35 36 37 38 | |
Immutable configuration for Pollux execution.
Provider and model are required—Pollux does not guess what you want. API keys are auto-resolved from standard environment variables.
Example
config = Config(provider="gemini", model="gemini-2.0-flash")
API key is automatically resolved from GEMINI_API_KEY¶
Source code in src/pollux/config.py
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 | |
Serializable Pollux handle for a deferred job.
Source code in src/pollux/deferred.py
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 | |
Functions¶
to_dict ¶
to_dict()
Serialize the handle for persistence.
Source code in src/pollux/deferred.py
56 57 58 | |
from_dict
classmethod
¶
from_dict(data)
Rebuild a handle from serialized data.
Source code in src/pollux/deferred.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
Normalized snapshot of a deferred job lifecycle.
Source code in src/pollux/deferred.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
Optional execution features for run() and run_many().
Source code in src/pollux/options.py
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 | |
Functions¶
response_schema_json ¶
response_schema_json()
Return JSON Schema for provider APIs.
Source code in src/pollux/options.py
171 172 173 | |
response_schema_model ¶
response_schema_model()
Return Pydantic schema class when one was provided.
Source code in src/pollux/options.py
175 176 177 | |
response_schema_hash ¶
response_schema_hash()
Return a stable hash of the JSON Schema.
Source code in src/pollux/options.py
179 180 181 | |
Bounded retry policy with exponential backoff and optional jitter.
Source code in src/pollux/retry.py
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 | |
Bases: TypedDict
Standard result envelope returned by Pollux.
status is "ok" when all answers are non-empty, "partial" when
some are empty, or "error" when all are empty.
Source code in src/pollux/result.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
Error Types¶
Bases: Exception
Base exception for all Pollux errors.
Source code in src/pollux/errors.py
11 12 13 14 15 16 | |
Bases: PolluxError
Configuration validation or resolution failed.
Source code in src/pollux/errors.py
19 20 | |
Bases: PolluxError
Source validation or loading failed.
Source code in src/pollux/errors.py
23 24 | |
Bases: PolluxError
Execution planning failed.
Source code in src/pollux/errors.py
27 28 | |
Bases: PolluxError
A Pollux internal error (bug) or invariant violation.
Source code in src/pollux/errors.py
31 32 | |
Bases: PolluxError
API call failed.
Providers attach retry metadata so core execution can perform bounded retries without brittle substring matching.
Source code in src/pollux/errors.py
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 | |
Bases: APIError
Rate limit exceeded (HTTP 429).
Source code in src/pollux/errors.py
67 68 | |
Bases: APIError
Cache operation failed.
Source code in src/pollux/errors.py
63 64 | |
Bases: PolluxError
Deferred job is not yet in a terminal state.
Source code in src/pollux/errors.py
71 72 73 74 75 76 77 78 79 | |