Skip to main content

Python SDK for COS (Cognitive Operating System) — AI reliability middleware by Protofine.ai

Project description

COS Python SDK

Python client for the COS (Cognitive Operating System) API — AI reliability middleware by Protofine.ai.

COS validates AI-generated text for hallucinations, returning confidence scores, risk levels, and flagged claims with corrections.

Install

pip install cos-sdk

Quick Start

from cos_sdk import COS

client = COS(api_key="cos_live_xxx")

# Validate AI-generated text
result = client.validate(
    text="According to a 2024 study, 90% of Fortune 500 companies use AI in production.",
    tier="tier_2",  # tier_1 (instant), tier_2 (AI review), tier_3 (multi-model)
)

print(f"Confidence: {result.confidence_score}")  # 0.0 to 1.0
print(f"Risk: {result.risk_level}")              # "low", "medium", "high"

for claim in result.flagged_claims:
    print(f"  Flag: {claim.claim}")
    print(f"  Why:  {claim.reason}")
    if claim.correction:
        print(f"  Fix:  {claim.correction}")

Streaming

Get results progressively — Tier 1 arrives in ~5ms, deeper tiers in 2-5 seconds:

for event in client.validate_stream("AI text to check", tier="tier_3"):
    if event.event == "t1_result":
        print(f"Quick check: {event.result.confidence_score}")
    elif event.event == "validation_complete":
        print(f"Full result: {event.result.confidence_score}")

Async

from cos_sdk import AsyncCOS

async with AsyncCOS(api_key="cos_live_xxx") as client:
    result = await client.validate("AI text to check")
    print(result.confidence_score)

Validation Tiers

Tier Speed Cost What it does
tier_1 ~5ms Free Heuristic pattern matching (fake stats, suspicious URLs, hedging)
tier_2 ~2s Low AI model review (Claude Haiku fact-checking)
tier_3 ~3s Medium Multi-model consensus (Haiku + Gemini)

Get Your API Key

  1. Go to cos.protofine.ai/console
  2. Sign in with your account
  3. Create a new API key
  4. Save it — you won't see it again

Error Handling

from cos_sdk import COS, AuthenticationError, RateLimitError

client = COS(api_key="cos_live_xxx")

try:
    result = client.validate("text to check")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Slow down — retry in {e.retry_after}s")

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

cos_sdk-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

cos_sdk-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file cos_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: cos_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for cos_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 306c57bfa9e61829f43b73a9a3e0099bfe3e83a4ede78c8e069ea8cdc637553d
MD5 029e888a14ecde8c4abd1712bb1d2068
BLAKE2b-256 27761402ba15da6d86705f3532d2302c39d99d197b2b05a82ca49a67b13f3cf0

See more details on using hashes here.

File details

Details for the file cos_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cos_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for cos_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b774df907f7615ba8036d754bcc047aaedbc1b44b6c760204a29068bcc2bf1
MD5 20fdea472b09afbd6084267eac1c0ce5
BLAKE2b-256 aa41ad6636f00dac54e9f925d3d94ed08dd911238cb6ec645cb135b6cc941471

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