Skip to main content

cognitivess — Python SDK

Official Python SDK for the CognitivessAI API. The platform is OpenAI- and Anthropic-compatible, so this SDK gives you both ergonomics in one package, talking to model Cognitivess-1.

pip install cognitivess
  • Sync and async clients (Cognitivess / AsyncCognitivess)
  • Streaming (SSE) for chat, messages and responses
  • Structured Outputs (response_format) pass-through
  • Typed exceptions, retries with backoff (honors Retry-After), timeout control
  • Reads .env automatically (no python-dotenv dependency)
  • Zero heavy deps — only httpx

Setup

Generate an API key in your CognitivessAI dashboard (looks like ssh-ed25519 AAAA...). It's shown only once. Then either pass it explicitly, export it, or put it in a .env file — the SDK reads .env automatically (no python-dotenv / load_dotenv() needed):

export COGNITIVESS_API_KEY="ssh-ed25519 AAAA..."
# .env  (in your project root / cwd)
COGNITIVESS_API_KEY=ssh-ed25519 AAAA...

The .env fallback only fills in variables that aren't already set in the environment, so explicit env vars or api_key= always win. Disable it with Cognitivess(env_file=None), or point elsewhere with Cognitivess(env_file="config/.env").

Quickstart

OpenAI style — chat completions

from cognitivess import Cognitivess

cog = Cognitivess()  # reads COGNITIVESS_API_KEY

resp = cog.chat.completions.create(
    model="Cognitivess-1",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello, how are you?"},
    ],
    max_tokens=128,
    temperature=0.7,
)
print(resp.choices[0].message.content)

Anthropic style — messages

msg = cog.messages.create(
    model="Cognitivess-1",
    max_tokens=128,
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(msg.content[0].text)

Streaming

# sync
for chunk in cog.chat.completions.create(
    model="Cognitivess-1",
    messages=[{"role": "user", "content": "Count to 5."}],
    max_tokens=64,
    stream=True,
):
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)
# async
import asyncio
from cognitivess import AsyncCognitivess

async def main():
    async with AsyncCognitivess() as cog:
        async for chunk in cog.chat.completions.create(
            model="Cognitivess-1",
            messages=[{"role": "user", "content": "Count to 5."}],
            max_tokens=64,
            stream=True,
        ):
            delta = chunk.choices[0].delta.content
            if delta:
                print(delta, end="", flush=True)

asyncio.run(main())

Structured Outputs

resp = cog.chat.completions.create(
    model="Cognitivess-1",
    messages=[{"role": "user", "content": "I spent $120 on dinner and $45 on supplies."}],
    max_tokens=512,
    temperature=0.1,
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "expenses",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "items": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "description": {"type": "string"},
                                "amount": {"type": "number"},
                            },
                            "required": ["description", "amount"],
                            "additionalProperties": False,
                        },
                    },
                    "total": {"type": "number"},
                },
                "required": ["items", "total"],
                "additionalProperties": False,
            },
        },
    },
)
print(resp.choices[0].message.content)  # JSON string

Responses API

r = cog.responses.create(
    model="Cognitivess-1",
    input="Say hi in one word.",
    max_output_tokens=16,
)
print(r.output_text)

List models

print(cog.models.list().data[0].id)

Configuration

cog = Cognitivess(
    api_key="...",            # optional, defaults to COGNITIVESS_API_KEY
    base_url="https://api.cognitivess.com/v1",  # override for self-hosted/dev
    timeout=60.0,             # seconds
    max_retries=2,            # retries on 429/5xx/conn errors, with backoff
    default_headers={"X-Tag": "prod"},  # merged into every request
    env_file=".env",          # auto-load .env (default); None to disable
)

Error handling

from cognitivess import AuthenticationError, RateLimitError, APIStatusError, APITimeoutError

try:
    cog.chat.completions.create(model="Cognitivess-1", messages=[...], max_tokens=64)
except AuthenticationError as e:    # 401 — bad/revoked key
    print("auth:", e.message, e.status_code)
except RateLimitError as e:         # 429 — rate limit / credits
    print("rate:", e.message)
except APITimeoutError:             # timeout
    ...
except APIStatusError as e:         # any other non-2xx
    print("status:", e.status_code, e.message)

Notes

  • This package is the SDK library. The cognitivess CLI (installed via curl | sh) is a separate tool; installing this SDK does not register a cognitivess console command, so the two coexist without conflict.
  • base_url already includes /v1. The SDK calls /chat/completions, /messages, /models, /responses relative to it. For self-hosted/dev, point it at e.g. http://localhost:8000/v1.
  • Responses objects are attribute-accessible (resp.choices[0].message.content) via a light wrapper — no Pydantic dependency.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognitivess-0.1.3.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

cognitivess-0.1.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file cognitivess-0.1.3.tar.gz.

File metadata

  • Download URL: cognitivess-0.1.3.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cognitivess-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d8055b026877f62c130b645ff8303b3316d8b2b9383834e506a50fc6189faf26
MD5 0e415ed2bb7cf907a7fc11cb05b3b847
BLAKE2b-256 42145a81ac8f4060f79a123ff0febdd8e5172fbf38e80cf13942eb5442fc30ff

See more details on using hashes here.

File details

Details for the file cognitivess-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: cognitivess-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cognitivess-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a7c039e197b547d720f240ec65586ceed29baed89d646c5b3f19c6f76d54fd5f
MD5 d41c3859c4232251f3400fdb3fbb54f0
BLAKE2b-256 c0abbf4c134d191cc2136eced19ea1d0865e711a246fc874c2718cefae81795c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page