API Reference¶
Quick reference for the current public API.
For provider-level feature differences, see Provider Capabilities.
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
|
The prompt to run. |
required |
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 (schema, reasoning, delivery mode). |
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
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 | |
Run multiple prompts with shared sources for source-pattern execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts
|
str | list[str] | tuple[str, ...]
|
One or more prompts to run. |
required |
sources
|
tuple[Source, ...] | list[Source]
|
Optional sources for shared context. |
()
|
config
|
Config
|
Configuration specifying provider and model. |
required |
options
|
Options | None
|
Optional additive features (schema, reasoning, delivery mode). |
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
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 | |
Core Types¶
A structured representation of a single input source.
Source code in src/pollux/source.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 | |
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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
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
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 | |
from_youtube
classmethod
¶
from_youtube(url)
Create a Source from a YouTube URL reference (no download).
Source code in src/pollux/source.py
78 79 80 81 82 83 84 85 86 87 88 | |
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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
content_hash ¶
content_hash()
Compute SHA256 hash of content for cache identity.
Source code in src/pollux/source.py
159 160 161 162 | |
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
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 | |
Optional execution features for run() and run_many().
Source code in src/pollux/options.py
20 21 22 23 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 | |
Functions¶
response_schema_json ¶
response_schema_json()
Return JSON Schema for provider APIs.
Source code in src/pollux/options.py
79 80 81 82 83 84 85 86 | |
response_schema_model ¶
response_schema_model()
Return Pydantic schema class when one was provided.
Source code in src/pollux/options.py
88 89 90 91 92 93 | |
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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
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 | |