### Quick Start with Anima Client Source: https://github.com/anima-labs-ai/python/blob/main/README.md Initialize the client, create an agent, and send an email. ```python from anima import Anima client = Anima(api_key="sk-...") # Create an agent agent = client.agents.create( org_id="org_123", name="Support Bot", slug="support-bot", ) # Send an email message = client.messages.send_email( agent_id=agent.id, to=["user@example.com"], subject="Hello from Anima", body="Your order has been shipped!", ) print(message.id) client.close() ``` -------------------------------- ### Install Anima SDK Source: https://github.com/anima-labs-ai/python/blob/main/README.md Install the package using pip. ```bash pip install anima-labs ``` -------------------------------- ### Register a webhook endpoint Source: https://github.com/anima-labs-ai/python/blob/main/README.md Create a webhook with specific events and authentication configuration. The auth credential is write-only and will not be returned by subsequent get or list calls. ```python from anima import WebhookAuthBearer webhook = client.webhooks.create( url="https://example.com/anima/webhook", events=["message.received"], # Also: WebhookAuthBasic(username=, password=), # WebhookAuthCustomHeader(header_name=, value=), WebhookAuthNone(). auth_config=WebhookAuthBearer(token="your-endpoint-token"), rate_limit_per_minute=120, # omit for unlimited max_attempts=5, # 1-10, default 3 ) print(webhook.id, webhook.auth_type) # -> "wh_..." "BEARER" ``` -------------------------------- ### Configure Anima client instance Source: https://github.com/anima-labs-ai/python/blob/main/README.md Shows how to initialize the Anima client with custom configuration parameters such as base_url, timeout, and max_retries. ```python client = Anima( api_key="sk-...", base_url="https://api.useanima.sh", # custom endpoint timeout=60.0, max_retries=5, ) ``` -------------------------------- ### Anima Client Initialization Source: https://github.com/anima-labs-ai/python/blob/main/README.md How to instantiate the Anima client with custom configuration parameters. ```APIDOC ## Anima Client Initialization ### Description Initialize the Anima SDK client to interact with the API. ### Parameters - **api_key** (string) - Required - Your Anima API key (sk-...) - **base_url** (string) - Optional - API base URL (default: https://api.useanima.sh) - **timeout** (float) - Optional - Request timeout in seconds (default: 30.0) - **max_retries** (int) - Optional - Max automatic retries on transient errors (default: 3) ### Example ```python client = Anima( api_key="sk-...", base_url="https://api.useanima.sh", timeout=60.0, max_retries=5, ) ``` ``` -------------------------------- ### Create and send an email draft Source: https://github.com/anima-labs-ai/python/blob/main/README.md Creates a draft using client.emails.drafts.create and sends it using client.emails.drafts.send, which atomically deletes the draft. ```python draft = client.emails.drafts.create( agent_id=agent.id, to=["user@example.com"], subject="Quarterly report", body="Numbers attached below.", ) message = client.emails.drafts.send(draft.id) # draft is deleted server-side ``` -------------------------------- ### Connect a headless browser extension Source: https://github.com/anima-labs-ai/python/blob/main/README.md Mint a one-time connect handoff URL for a browser-extension worker. The returned connect_url is used to complete the handshake. ```python handoff = client.extension.connect(agent_id="agent_123", ttl="15m") print(handoff.connect_url) # open in the extension worker to complete the handshake ``` -------------------------------- ### client.extension Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing browser-extension worker connections. ```APIDOC ## client.extension - connect(*, agent_id?, ttl?): Mint a one-time connect handoff for a headless browser-extension worker. ``` -------------------------------- ### client.organizations Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing organization accounts and API keys. ```APIDOC ## client.organizations - create(*, name, slug, clerk_org_id?, tier?, settings?): Create an organization - get(org_id): Get organization details - list(*, cursor?, limit?, query?): List organizations - update(org_id, *, name?, slug?, clerk_org_id?, tier?, settings?): Update an organization - delete(org_id): Delete an organization - rotate_key(org_id): Rotate the master API key ``` -------------------------------- ### client.agents Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing AI agents, including creation, retrieval, listing, updating, deletion, and API key rotation. ```APIDOC ## client.agents ### Methods - **create(*, org_id, name, slug, email?, provision_phone?, metadata?)**: Create a new agent. - **get(agent_id)**: Get an agent by ID. - **list(*, cursor?, limit?, org_id?, status?, query?)**: List agents with pagination. - **update(agent_id, *, name?, slug?, status?, metadata?)**: Update agent fields. - **delete(agent_id)**: Delete an agent. - **rotate_key(agent_id)**: Rotate an agent's API key. ``` -------------------------------- ### client.phones Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for provisioning and managing phone numbers. ```APIDOC ## client.phones ### Methods - **provision(*, agent_id, country_code?, area_code?, capabilities?)**: Provision a phone number. - **get(phone_id)**: Get phone details. - **list(*, cursor?, limit?, agent_id?)**: List phone numbers. - **release(phone_id)**: Release a phone number. - **update_config(phone_id, *, is_primary?, ten_dlc_status?, metadata?)**: Update phone configuration. ``` -------------------------------- ### Anima.construct_webhook_event Source: https://github.com/anima-labs-ai/python/blob/main/README.md Verifies the signature and parses the raw request body into a structured event object. ```APIDOC ## Anima.construct_webhook_event ### Description Verifies the signature and constructs an event model from the raw request body. ### Parameters - **payload** (bytes) - Required - The raw request body bytes. - **signature** (string) - Required - The value from the X-Anima-Signature header. - **timestamp** (string) - Required - The value from the X-Anima-Timestamp header. - **secret** (string) - Required - The webhook secret key. ### Returns - **event** (WebhookEvent) - A parsed event object. ### Errors - **AnimaError** - Raised if the signature is invalid or the payload cannot be parsed. ``` -------------------------------- ### client.webhooks Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for registering and managing webhook endpoints and delivery attempts. ```APIDOC ## client.webhooks - create(*, url, events, description?, active?, auth_config?, rate_limit_per_minute?, max_attempts?): Register a webhook endpoint - get(webhook_id): Get webhook details - list(*, cursor?, limit?): List webhooks - update(webhook_id, *, url?, events?, description?, active?, auth_config?, rate_limit_per_minute?, max_attempts?): Update a webhook - delete(webhook_id): Delete a webhook - test(webhook_id, *, event?): Send a test event - list_deliveries(webhook_id, *, cursor?, limit?): List delivery attempts ``` -------------------------------- ### client.security Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for monitoring security status and events. ```APIDOC ## client.security - get_scanner_status(*, org_id): Whether AI scanning is running - list_events(*, org_id, agent_id?, type?, severity?, cursor?, limit?): List security events ``` -------------------------------- ### client.domains Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing custom domains, including verification, DNS records, and deliverability statistics. ```APIDOC ## client.domains - add(*, domain): Add a custom domain - get(domain_id): Get domain details - list(): List all domains - delete(domain_id): Remove a domain - update(domain_id, *, feedback_enabled?): Update domain settings - verify(domain_id): Trigger domain verification - dns_records(domain_id): Get required DNS records - deliverability(domain_id): Get deliverability statistics - zone_file(domain_id): Export the domain zone file ``` -------------------------------- ### Send an email with an attachment Source: https://github.com/anima-labs-ai/python/blob/main/README.md Sends an email using send_email, requiring a dictionary for the attachment with either content or url. ```python message = client.messages.send_email( agent_id=agent.id, to=["user@example.com"], subject="Your invoice", body="Invoice attached.", attachments=[ {"filename": "invoice.pdf", "contentType": "application/pdf", "content": pdf_base64}, ], ) ``` -------------------------------- ### Handle Anima API exceptions Source: https://github.com/anima-labs-ai/python/blob/main/README.md Demonstrates how to catch specific typed exceptions like AuthenticationError, NotFoundError, and RateLimitError when interacting with the Anima client. ```python from anima import Anima, AuthenticationError, NotFoundError, RateLimitError, APIError client = Anima(api_key="sk-...") try: agent = client.agents.get("nonexistent") except AuthenticationError: print("Invalid API key") except NotFoundError: print("Agent not found") except RateLimitError: print("Rate limited -- back off and retry") except APIError as e: print(f"API error {e.status_code}: {e.message}") ``` -------------------------------- ### fastapi_webhook_dependency Source: https://github.com/anima-labs-ai/python/blob/main/README.md A FastAPI dependency that handles signature verification and event parsing automatically. ```APIDOC ## fastapi_webhook_dependency ### Description Creates a FastAPI dependency that verifies the webhook signature and returns the parsed event object. ### Parameters - **secret** (string) - Required - The webhook secret key. ### Usage Use with FastAPI's `Depends` to inject the parsed `WebhookEvent` into your route handler. ``` -------------------------------- ### Verify webhooks with FastAPI dependency Source: https://github.com/anima-labs-ai/python/blob/main/README.md Use the fastapi_webhook_dependency to automatically verify and parse incoming webhook events within a FastAPI route. ```python from anima import fastapi_webhook_dependency webhook_dep = fastapi_webhook_dependency("whsec_...") @app.post("/webhooks") async def handle(event: WebhookEvent = Depends(webhook_dep)): print(event.event, event.occurred_at) ``` -------------------------------- ### client.emails.drafts Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing email drafts, including creation, listing, and atomic sending. ```APIDOC ## client.emails.drafts ### Methods - **create(*, agent_id, from_identity_id?, to?, cc?, bcc?, subject?, body?, body_html?, in_reply_to?, references?, metadata?)**: Create a draft. - **get(draft_id)**: Get a draft by ID. - **list(*, cursor?, limit?, agent_id?)**: List drafts with pagination. - **send(draft_id)**: Send the draft. - **delete(draft_id)**: Discard a draft. ``` -------------------------------- ### client.vault Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for managing agent vaults, credentials, and password generation. ```APIDOC ## client.vault - provision(*, agent_id): Provision a vault for an agent - deprovision(*, agent_id): Deprovision an agent's vault - list_credentials(*, agent_id, type?): List stored credentials - get_credential(credential_id): Get a credential by ID - create_credential(*, agent_id, type, name, notes?, login?, card?, identity?, fields?, favorite?, generate_password?): Store a new credential - update_credential(credential_id, *, name?, notes?, login?, card?, identity?, fields?, favorite?): Update a credential - delete_credential(credential_id): Delete a credential - search(*, agent_id, search, type?): Search credentials - generate_password(*, length?, uppercase?, lowercase?, numbers?, symbols?): Generate a secure password - get_totp(credential_id): Get a TOTP code - status(agent_id): Get vault status - sync(agent_id): Force vault sync ``` -------------------------------- ### Verify and parse webhooks manually Source: https://github.com/anima-labs-ai/python/blob/main/README.md Use Anima.verify_webhook_signature to check validity or Anima.construct_webhook_event to verify and parse the payload in one step. Ensure the raw request body is used, as re-serialized bodies will fail verification. ```python from anima import Anima, AnimaError # The raw request body. A body that has been parsed and re-serialised will not # verify, even when the delivery is genuine — the MAC covers bytes. payload = request.body signature = request.headers["x-anima-signature"] timestamp = request.headers["x-anima-timestamp"] secret = "whsec_..." # Option 1: verify only is_valid = Anima.verify_webhook_signature(payload, signature, timestamp, secret) # Option 2: verify and parse in one step try: event = Anima.construct_webhook_event(payload, signature, timestamp, secret) # The payload is flat — there is no `data` envelope to unwrap. Event-specific # fields keep their wire names and are available on the model. print(event.event, event.occurred_at, event.model_extra["messageId"]) except AnimaError: print("Invalid signature") ``` -------------------------------- ### Async Usage with AsyncAnima Source: https://github.com/anima-labs-ai/python/blob/main/README.md Use the AsyncAnima client for asynchronous operations. ```python import asyncio from anima import AsyncAnima async def main(): async with AsyncAnima(api_key="sk-...") as client: agents = await client.agents.list(org_id="org_123") for agent in agents.items: print(agent.name) asyncio.run(main()) ``` -------------------------------- ### client.voices Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for browsing the multilingual voice catalog. ```APIDOC ## client.voices ### Methods - **list(*, language?, gender?)**: List catalog voices, optionally filtered by language or gender. ``` -------------------------------- ### client.messages Source: https://github.com/anima-labs-ai/python/blob/main/README.md Methods for sending and managing messages, including email, SMS, semantic search, and attachment handling. ```APIDOC ## client.messages ### Methods - **send_email(*, agent_id, to, subject, body, cc?, bcc?, body_html?, attachments?, in_reply_to?, references?, headers?, metadata?)**: Send an email. - **send_sms(*, agent_id, to, body, media_urls?, metadata?)**: Send an SMS. - **get(message_id)**: Get a message by ID. - **list(*, cursor?, limit?, agent_id?, thread_id?, channel?, direction?, date_from?, date_to?)**: List messages with filters. - **search(query, *, agent_id?, channel?, direction?, status?, date_from?, date_to?, cursor?, limit?)**: Full-text search messages. - **semantic_search(query, *, agent_id?, limit?, threshold?)**: Search messages by meaning. - **upload_attachment(message_id, *, filename, mime_type, size_bytes)**: Upload an attachment. - **get_attachment_url(attachment_id)**: Get a download URL for an attachment. ``` -------------------------------- ### List voices filtered by language Source: https://github.com/anima-labs-ai/python/blob/main/README.md Retrieves a list of voices from the catalog, optionally filtered by language, and prints their metadata and sample URLs. ```python # Only Spanish voices result = client.voices.list(language="es") for voice in result["voices"]: print(voice.id, voice.name, voice.language, voice.descriptors) if voice.sample_url: # vendor-neutral preview served from the API host print("preview:", voice.sample_url) ``` -------------------------------- ### Error Handling Source: https://github.com/anima-labs-ai/python/blob/main/README.md Handling typed exceptions raised by the Anima SDK. ```APIDOC ## Error Handling ### Description The SDK raises typed exceptions that subclass `AnimaError`. Users should catch these to handle specific failure scenarios. ### Exception Types - **AuthenticationError**: Raised for invalid API keys. - **NotFoundError**: Raised when a requested resource is not found. - **RateLimitError**: Raised when the API rate limit is exceeded. - **APIError**: Base class for other API-related errors, providing `status_code` and `message`. ### Example ```python try: agent = client.agents.get("nonexistent") except AuthenticationError: print("Invalid API key") except NotFoundError: print("Agent not found") except RateLimitError: print("Rate limited -- back off and retry") except APIError as e: print(f"API error {e.status_code}: {e.message}") ``` ``` -------------------------------- ### Accessing Unwrapped Response Shapes Source: https://github.com/anima-labs-ai/python/blob/main/README.md The SDK automatically unwraps single-key response envelopes, returning the payload directly. ```python credentials = client.vault.list_credentials(agent_id=...) # list[VaultCredential] password = client.vault.generate_password(length=24) # str ``` -------------------------------- ### Anima.verify_webhook_signature Source: https://github.com/anima-labs-ai/python/blob/main/README.md Verifies the authenticity of a webhook request using the provided signature, timestamp, and secret. ```APIDOC ## Anima.verify_webhook_signature ### Description Verifies the HMAC-SHA256 signature of a webhook delivery. ### Parameters - **payload** (bytes) - Required - The raw request body bytes. - **signature** (string) - Required - The value from the X-Anima-Signature header. - **timestamp** (string) - Required - The value from the X-Anima-Timestamp header. - **secret** (string) - Required - The webhook secret key. ### Returns - **is_valid** (boolean) - Returns True if the signature is valid, False otherwise. ``` -------------------------------- ### Perform semantic search on messages Source: https://github.com/anima-labs-ai/python/blob/main/README.md Uses semantic_search to rank messages by meaning rather than keywords, returning results with a similarity score. ```python results = client.messages.semantic_search("unpaid invoices from suppliers", limit=5) for r in results: print(f"{r.similarity:.2f} {r.channel} {r.content[:60]}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.