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.

The return types follow the OpenAI Python SDK schema exactly, so migrating a script is a one-line client swap:

completion = client.generate_completion("hi")
print(completion.choices[0].message.content)
print(completion.usage.prompt_tokens, completion.usage.completion_tokens)

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)

Non-streaming

Returns a ChatCompletion matching the OpenAI response shape.

from analogaisdk import AnalogAIClient

client = AnalogAIClient(agent_id="my-agent", user_id="my-user")

completion = client.generate_completion("are humans mortal?")
print(completion.choices[0].message.content)
print("prompt_tokens    =", completion.usage.prompt_tokens)
print("completion_tokens=", completion.usage.completion_tokens)
print("total_tokens     =", completion.usage.total_tokens)

Streaming

Yields ChatCompletionChunk objects. The final chunk carries usage with token counts (the SDK sends stream_options={"include_usage": true} automatically).

for chunk in client.generate_streaming_completion("are humans mortal?"):
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
    if chunk.usage is not None:
        print()
        print(chunk.usage.prompt_tokens, chunk.usage.completion_tokens)

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-5.4-mini",  # optional, provider-prefixed
    temperature=0.2,
)

Response schema

  • ChatCompletion.id / object / created / model
  • ChatCompletion.choices[i].index / .finish_reason
  • ChatCompletion.choices[i].message.role / .content / .tool_calls
  • ChatCompletion.usage.prompt_tokens / .completion_tokens / .total_tokens
  • ChatCompletion.raw — the parsed JSON body from the server, unchanged

For streaming:

  • ChatCompletionChunk.choices[i].delta.role / .content / .tool_calls
  • ChatCompletionChunk.choices[i].finish_reason
  • ChatCompletionChunk.usageNone on intermediate chunks, populated on the final chunk when the server honours stream_options.include_usage.

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.7.0.tar.gz (6.0 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.7.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file analogaisdk-0.7.0.tar.gz.

File metadata

  • Download URL: analogaisdk-0.7.0.tar.gz
  • Upload date:
  • Size: 6.0 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.7.0.tar.gz
Algorithm Hash digest
SHA256 25d4337a45d7b935d35d24044fe311e99c6b2a88699ef613a955aafb70305e48
MD5 7f119e7e829d1a1bc9e6c7db9aa86598
BLAKE2b-256 19220fe93dd14a123da87adfca6faf711b9a7304bc2fecf3ed7510001784675b

See more details on using hashes here.

File details

Details for the file analogaisdk-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: analogaisdk-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddcbe029dd4b8562e31c43a6487951b37fb92c6032956ca79a37dd117d80eb85
MD5 81ee5c4e7135fca88bc58df08571024e
BLAKE2b-256 47d99f066bf7476c64949241ac153eaeefe18abe769b69582ef2c8baa3999fcc

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