insideai
Python client for the InsideAI API.
pip install insideai
Quickstart
import os
from insideai import InsideAI, create_chat, wait_for_chat
iai = InsideAI(api_key=os.environ["INSIDEAI_API_KEY"])
chat = create_chat(iai, "Summarize last quarter's findings.")
print(wait_for_chat(iai, chat["id"])["answer_text"])
InsideAI(...) holds your key, base URL and a pooled HTTP session. Build it once and pass it as the
first argument to everything else.
InsideAI answers asynchronously, so create_chat returns straight away. wait_for_chat polls for
you; call get_chat yourself if you would rather drive the loop (a job queue, a webhook, a UI that
shows progress).
Examples
Complete, runnable scripts ship in the source distribution under examples/, and are the fastest
way to see the shape of an integration:
| Example | Shows |
|---|---|
examples/ask_a_question.py |
The smallest end-to-end call: ask, wait, print. |
examples/act_as_a_user.py |
Asking on behalf of one of your own users, and confirming act-as took effect before you do. |
examples/run_a_library_prompt.py |
Looking a prompt up by safe_name so its text stays editable in InsideAI. |
examples/continue_a_conversation.py |
Follow-up questions in one thread. |
examples/embed_session_endpoint.py |
The one backend endpoint embedded chat needs — and why it mints for the signed-in user only. |
export INSIDEAI_API_KEY=iaiak_…
python examples/ask_a_question.py "What changed this week?"
API keys
Keys never expire and are revoked from the InsideAI admin UI. They come in two kinds:
- Client-wide — acts as your organization's API service account, and may act as any member of your
org by passing
act_as=<their email>. - User-specific — always acts as one person. Passing
act_asto one of these is an error rather than a silent no-op, so a misconfigured integration fails loudly.
me(iai) # the service account
me(iai, act_as="alice@example.com") # Alice, with Alice's permissions
Acting as someone means exactly that: their org, their permissions, their row-level access, and anything created shows up in their own InsideAI history. You can only act as an active member of the key's organization.
Never send a key to a browser. For embedded chat, mint a one-time code server-side with
embed_session and hand that to the frontend — see
examples/embed_session_endpoint.py and
@cpcyber/insideai.
Functions
Every function takes the client first and an optional act_as=.
| Function | Returns |
|---|---|
me(iai) |
{"email", "display_name", "client", "acting_as", "key"} |
prompts(iai, safe_name=None) |
Visible prompt-library prompts, fully paged. safe_name is the stable slug to key config off, and filtering on it returns at most one. |
create_chat(iai, ask, conversation=None, project=None) |
The new chat. InsideAI answers asynchronously — poll it. Omit conversation to start a new thread. |
get_chat(iai, chat_id) |
{"id", "ask", "answer_text", "answer_blocks", "done", "ts_asked", "ts_answered", "conversation", "eta"} |
wait_for_chat(iai, chat_id, interval=2, timeout=120) |
The same chat once done. Raises InsideAITimeoutError rather than handing back a half-answered one. |
chats(iai, conversation=None) |
Every chat the acting user can see. |
embed_session(iai, email=None) |
{"enabled", "code", "chat_url", "mini_url", "expires_in"} for mounting embedded chat. |
answer_text is the answer flattened to plain text. answer_blocks is the original display-block
list ({display, params}) if you want to render charts and images yourself.
Errors
InsideAIError for anything that isn't a 2xx, carrying .status and .payload. Two subclasses are
worth catching on their own: InsideAIAuthError for 401/403 — a rejected key never becomes valid on
a retry — and InsideAITimeoutError when wait_for_chat gives up on a chat that is still being
answered. GETs retry twice on connection failures and 502/503/504; nothing else is retried, since a
4xx is an answer.
from insideai import InsideAIAuthError, InsideAIError
try:
chat = create_chat(iai, "hello")
except InsideAIAuthError:
... # key revoked, or acting as someone you may not
except InsideAIError as exc:
log.warning("InsideAI %s: %s", exc.status, exc.payload)
Other environments
base_url defaults to production. Point it elsewhere if InsideAI gave you a different endpoint:
iai = InsideAI(api_key=..., base_url="https://your-insideai-endpoint/")
Layout
Import everything from the package root — from insideai import create_chat — which is the surface
this package keeps stable. Underneath:
| Module | What it owns |
|---|---|
client.py |
InsideAI(): the key, the base URL, the pooled session and its retry policy. |
api.py |
Everything that knows about HTTP — URL building, the act-as header, pagination, turning a failure into an exception. The endpoint modules never touch requests. |
endpoints/ |
One module per /api/v1/ resource: chats.py, prompts.py, identity.py, embed.py. Each knows its path and its arguments, nothing more. |
errors.py |
The exception classes, and the mapping from a status code onto one. |
constants.py |
The strings both halves share: default base URL, API prefix, auth scheme, act-as header. |
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file insideai-0.2.0.tar.gz.
File metadata
- Download URL: insideai-0.2.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05858d2bbd375cd9ef0de404317503f2f2d9b13ba930e78957a01f53a3ccbd8
|
|
| MD5 |
fdaf8a6ef4b1f4789f4f69be0940ce7c
|
|
| BLAKE2b-256 |
185b3b3ef1513724234ac89b8ddbd0097a3894fab622a9862a7ea016a49abac8
|
File details
Details for the file insideai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: insideai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
996eaaea88a4d8e5fd8fc8a2cc5341928a411636a30d08583becf3ef6fb09850
|
|
| MD5 |
0094d6289082d79168d5cb55e097f6b9
|
|
| BLAKE2b-256 |
05521193dabc6a1ff27dc9ab7599cf1e6c9cab3c4ea058747d2c709acb9145cf
|