Talkory Python SDK
Ask once, hear from up to 5 LLMs (GPT, Claude, Gemini, Grok, Perplexity), and get back an AI consensus - all from typed, idiomatic Python. Install with pip install talkory.
pip install talkory
# quickstart.py
from talkory import Talkory
client = Talkory() # reads TALKORY_API_KEY
result = client.queries.run(
"Best commuter motorcycles under $5000?"
)
print(result.consensus)
print(result.confidence)Installation
The SDK targets Python 3.9+, is built on httpx and Pydantic v2, and ships fully typed with a py.typed marker so your editor and type checker understand every response shape.
pip install talkory| Requirement | Value |
|---|---|
| Python | 3.9, 3.10, 3.11, 3.12, 3.13 |
| Dependencies | httpx, pydantic v2 |
| Typing | Fully typed (py.typed) |
| License | MIT |
Quickstart
Every response is a typed object: result.consensus is the synthesized answer, result.common_answer is the content every model agreed on, and result.confidence is a 0-100 score.
from talkory import Talkory
client = Talkory() # reads TALKORY_API_KEY from environment
result = client.queries.run("Best commuter motorcycles under $5000?")
print(result.consensus) # synthesized answer
print(result.common_answer) # agreed-upon content
print(result.confidence) # 0-100 confidence
print(result.charged) # USD costAuthentication
Create a key at app.talkory.ai โ Settings โ API Keys, then either set it as an environment variable or pass it explicitly:
export TALKORY_API_KEY="tk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"from talkory import Talkory
# reads TALKORY_API_KEY automatically
client = Talkory()
# or pass a key explicitly
client = Talkory(api_key="tk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")repr() output, and every request is sent over HTTPS with a talkory-python/{version} python/{py_version} User-Agent.Sync & async clients
Use Talkory for scripts and simple sync code, or AsyncTalkory as an async context manager inside asyncio applications.
import asyncio
from talkory import AsyncTalkory
async def main():
async with AsyncTalkory() as client:
result = await client.queries.run("Best NAS for home use?")
print(result.consensus)
asyncio.run(main())Streaming
client.queries.stream() yields typed events as each model responds, ending with a done event carrying the consensus.
for event in client.queries.stream("Compare Python web frameworks in 2026"):
if event.type == "model_chunk":
print(event.chunk, end="", flush=True)
elif event.type == "done":
print("\n\nConsensus:", event.consensus)Key features
- Model selection. Choose up to 10 models per query, or omit the field to run everything on your plan.
- Recursive review. Optional self-review round where models critique and improve their own answers before consensus.
- Localization. Pass a country code to localise answers.
- Deferred consensus. Run queries cheaply with
consensus=False, then compute the consensus later viaqueries.consensus(). - Fire-and-forget. Create a query, then poll or wait for the result asynchronously.
- Wallet safety. The SDK never auto-retries paid POST requests, so a network blip can't double-charge your wallet.
Client reference
SYNCclient.queries.run(prompt, **kwargs)Paid ยท charged from wallet
Blocking call: sends the prompt, waits for every model plus the consensus, and returns one typed result. The simplest way to use the SDK. Accepts the same options as the API's POST /v1/query/sync (models, country, recursive, consensus) as keyword arguments.
result = client.queries.run(
"Best commuter motorcycles under $5000?",
models=["gpt", "claude", "gemini"],
recursive=False,
)
print(result.consensus, result.common_answer, result.confidence, result.charged)SYNCclient.queries.stream(prompt, **kwargs)Paid ยท charged from wallet
Returns a generator of typed events as each model responds live, mirroring the API's Server-Sent Events stream. Iterate it with a for loop; the final done event carries consensus, common_answer, confidence, and charged.
for event in client.queries.stream("Compare Python web frameworks in 2026"):
if event.type == "model_chunk":
print(event.chunk, end="", flush=True)
elif event.type == "model_result":
print(f"\n{event.model_id} scored {event.score}")
elif event.type == "done":
print("\n\nConsensus:", event.consensus)SYNCclient.queries.create() / .wait(id)Paid ยท charged from wallet
Fire-and-forget pattern: create() starts a run and returns immediately with an id, so a dropped connection never loses the run. Call wait(id) later (or poll retrieve(id)) to fetch the finished result once it is ready.
query = client.queries.create("Best commuter bikes under $5000?")
print(query.id) # save this - the run continues even if you disconnect
result = client.queries.wait(query.id) # blocks until status leaves "running"
print(result.consensus)SYNCclient.queries.consensus(id)Paid ยท idempotent
Generates the consensus and common answer for a query that was run with consensus=False. If the consensus already exists it is returned as-is with charged=0, so calling it twice never double-charges.
result = client.queries.run("Best NAS for home use?", consensus=False)
consensus = client.queries.consensus(result.id)
print(consensus.consensus, consensus.confidence)SYNCclient.queries.retrieve(id) / .list()Free ยท no wallet charge
retrieve(id) fetches a single query by id (used for polling or recovering after a dropped stream). list() returns your past queries, newest first, with limit and cursor for pagination.
query = client.queries.retrieve("7f9e4c2a-1b8f-4a21-9d3c-e77aa53b6c10")
print(query.status)
for q in client.queries.list(limit=20):
print(q.id, q.prompt, q.status)SYNCmodels.list() / health.check() / wallet.get() / usage.get()Free ยท no wallet charge
Utility calls that never touch your wallet: list available models, check live provider health, read your wallet balance, or pull aggregated usage for your key.
print(client.models.list())
print(client.health.check().status)
print(client.wallet.get().balance)
print(client.usage.get().requests.total)Error handling
The SDK raises typed exceptions carrying code, status, message, and request_id, so you can branch on error type or log the request id for support.
from talkory import Talkory, RateLimitError, InsufficientBalanceError, TalkoryError
client = Talkory()
try:
result = client.queries.run("Best commuter motorcycles under $5000?")
except RateLimitError as e:
print("slow down:", e.request_id)
except InsufficientBalanceError as e:
print("top up your wallet:", e.message)
except TalkoryError as e:
print(e.code, e.status, e.message, e.request_id)| Exception | When it happens |
|---|---|
RateLimitError | Too many requests for your key; check request_id and back off. |
InsufficientBalanceError | Wallet has no balance for a paid call. |
TalkoryError | Base class for all other API errors; carries code, status, message, request_id. |
Security
| Property | Behavior |
|---|---|
| Key resolution | Explicit api_key parameter, or TALKORY_API_KEY environment variable. |
| Key redaction | Keys never appear in logs, exceptions, or repr() output. |
| Transport | HTTPS enforced for every request. |
| Telemetry | Zero telemetry collected by the SDK. |
| User-Agent | talkory-python/{version} python/{py_version} |
FAQ
How do I install the Talkory Python SDK?
Run pip install talkory. It requires Python 3.9+ and depends on httpx and Pydantic v2. The package ships fully typed with a py.typed marker.
How does the Talkory Python SDK authenticate?
Set the TALKORY_API_KEY environment variable and call Talkory() with no arguments, or pass an explicit key with Talkory(api_key="tk_live_xxxxxxxx"). Keys are redacted from logs, exceptions, and repr output.
Does the Talkory Python SDK support async?
Yes. Use AsyncTalkory as an async context manager for asyncio-based applications, alongside the synchronous Talkory client for scripts.
Can I stream responses with the Talkory Python SDK?
client.queries.stream(prompt) yields events as each model responds, including model_chunk events for live text and a final done event with the consensus.
Need a key? Head to your API settings. Prefer REST? See the API documentation. Package details, release history and older versions live on PyPI โ, and the source is on GitHub โ.