Skip to main content

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 (default https://cloud.analogai.net:8010; set to http://localhost:8010 for 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

analogaisdk-0.5.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

analogaisdk-0.5.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

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

Hashes for analogaisdk-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c1cb47febf1ee4ae085a24c7305c203755226e75f5572d803ef11e72c4242cfc
MD5 45e00bcde71982cd5d87d6a7023578ae
BLAKE2b-256 efed44d31233eb703183fcefd21a7de3ca0c94331374c8c8727e9455346dd181

See more details on using hashes here.

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

Hashes for analogaisdk-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de1d3e27b2076b996c8783a1b1665b4c83ab2840f4b4f04f0bbf0d387a622002
MD5 ed58049225bc41905a8723e20a30e12d
BLAKE2b-256 5ec6755c755ee25f9db0b3d035a7d88ad925f1e8e04568e952a381706bac1deb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page