Minimal Python SDK for AnalogAI completion endpoints
Project description
AnalogAI SDK (minimal)
Tiny Python client for the Deepthink OpenAI-compatible chat server
(analogai.deepthink.chat). It calls POST {CHAT_BASE_URL}/v1/chat/completions
— a stateful endpoint: memory tenancy is keyed by user_id + agent_id
(both created server-side on first use), Deepthink memory is retrieved per
turn, and messages are ingested in the background.
Install
pip install analogaisdk
Setup
Set environment variables in .env:
CHAT_BASE_URL(defaulthttps://cloud.analogai.net:8010; set tohttp://localhost:8010for a local server)ANALOGAI_API_KEY(optional, if your server requires auth)ANALOGAI_MODEL(optional; server default is used when omitted)
Usage
from analogaisdk import AnalogAIClient
client = AnalogAIClient(agent_id="my-agent", user_id="my-user")
# Non-streaming (default).
print(client.generate_completion("are humans mortal?"))
# Streaming.
for chunk in client.generate_streaming_completion("are humans mortal?"):
print(chunk, end="", flush=True)
Working memory
Working memory (a string or list of strings) is appended to the LLM system prompt alongside the Deepthink memory:
client.generate_completion(
"is Socrates mortal?",
working_memory=["Socrates is a human"],
)
Explicit messages and model
client.generate_completion(
messages=[
{"role": "user", "content": "Say hello"},
],
model="azure:gpt-4o-mini", # optional, provider-prefixed
temperature=0.2,
)
Token usage and per-request USD cost
Every call surfaces the gateway's usage block (same field names as the
OpenAI API: prompt_tokens, completion_tokens, total_tokens) plus a
USD cost computed from a pricing table.
Built-in defaults price gpt-5.4-mini at $0.75 per 1M prompt tokens
and $4.50 per 1M completion tokens. Override or extend via the
pricing= constructor argument (values are USD per 1,000,000 tokens):
client = AnalogAIClient(
agent_id="my-agent",
user_id="my-user",
pricing={
"gpt-5.4-mini": {"prompt": 0.75, "completion": 4.50},
"azure:gpt-4o-mini": {"prompt": 0.15, "completion": 0.60},
},
print_usage=True, # also prints a stderr summary per request
)
Non-streaming — the return value is still a str, plus usage/cost:
result = client.generate_completion("are humans mortal?")
print(result) # assistant text
print(result.prompt_tokens) # int
print(result.completion_tokens) # int
print(result.total_tokens) # int
print(result.cost_usd) # float, USD
print(result.usage.as_dict()) # full breakdown incl. prompt/completion cost
Streaming — .usage is populated once the iterator is drained (the SDK
sends stream_options={"include_usage": True} so OpenAI-compatible
gateways emit a final chunk carrying the usage block):
stream = client.generate_streaming_completion("are humans mortal?")
for chunk in stream:
print(chunk, end="", flush=True)
print(stream.usage.prompt_tokens, stream.usage.completion_tokens, stream.usage.total_cost_usd)
The most recent usage is also cached on the client as client.last_usage.
Set ANALOGAISDK_PRINT_USAGE=1 in the environment (or pass
print_usage=True) to print a one-line summary to stderr after every
request:
[analogaisdk] model=gpt-5.4-mini prompt_tokens=812 completion_tokens=134 total_tokens=946 cost_usd=0.001212
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file analogaisdk-0.5.0.tar.gz.
File metadata
- Download URL: analogaisdk-0.5.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1cb47febf1ee4ae085a24c7305c203755226e75f5572d803ef11e72c4242cfc
|
|
| MD5 |
45e00bcde71982cd5d87d6a7023578ae
|
|
| BLAKE2b-256 |
efed44d31233eb703183fcefd21a7de3ca0c94331374c8c8727e9455346dd181
|
File details
Details for the file analogaisdk-0.5.0-py3-none-any.whl.
File metadata
- Download URL: analogaisdk-0.5.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de1d3e27b2076b996c8783a1b1665b4c83ab2840f4b4f04f0bbf0d387a622002
|
|
| MD5 |
ed58049225bc41905a8723e20a30e12d
|
|
| BLAKE2b-256 |
5ec6755c755ee25f9db0b3d035a7d88ad925f1e8e04568e952a381706bac1deb
|