Letterbook Python SDK
Send AI chat turns or explicit support events to Letterbook so customer issues become conversations.
Turn-based detection
Each record_turn call captures one turn in the conversation. It does not create a ticket by itself. Letterbook queues the turns, waits for the conversation to go quiet, scans the transcript on the backend with an LLM, and creates a ticket only when it finds a relevant customer issue.
import letterbook
result = letterbook.record_turn(
user_id="user123",
event="user_message",
model="gpt_4",
input="The checkout page is broken and I was charged twice.",
output="I am sorry, I cannot fix billing issues from here.",
convo_id="conv789",
customer_email="customer@example.com",
debounce_seconds=300,
properties={
"system_prompt": "you are a helpful assistant",
"experiment": "experiment_a",
},
attachments=[
{
"type": "text",
"name": "Additional Info",
"value": "A very long document",
"role": "input",
}
],
)
print(result.queued, result.evaluation_after_seconds)
Set LETTERBOOK_API_KEY, or instantiate letterbook.Letterbook(api_key=...) for explicit configuration.
Set debounce_seconds to control how long Letterbook waits after the last message before evaluating the conversation.
If OpenTelemetry is configured in your app, the SDK automatically propagates the active trace context with each capture request. You can install letterbook-ai-chat[otel] if your app does not already include OpenTelemetry.
If customer_email is omitted, the SDK looks for properties["customer_email"], properties["email"], or an email-shaped user_id.
Email is only required if Letterbook promotes the capture to a ticket.
letterbook.capture_turn(...) and letterbook.capture(...) are deprecated compatibility aliases for letterbook.record_turn(...).
Push-based conversation creation
When your app already knows a tool call should create a support conversation, call create_conversation directly.
conversation = letterbook.create_conversation(
customer_email="customer@example.com",
customer_name="Customer",
subject="Checkout tool failed",
message="The checkout tool failed after charging the card twice.",
priority="high",
external_id="tool-call-123",
metadata={
"source": "ai_tool",
"session_id": "session_789",
},
)
print(conversation.id, conversation.url)
API-key REST helpers
The SDK also wraps the existing API-key endpoints:
letterbook.list_conversations(status="open", page_size=50)
letterbook.get_conversation("conv_123")
letterbook.add_conversation_note(
"conv_123",
author_email="agent@example.com",
content="Investigated from the external workflow.",
mentioned_user_emails=["teammate@example.com"],
)
letterbook.delete_user("user_123", confirm_email="agent@example.com")
Framework adapters
Framework adapters are optional and do not add hard dependencies to the base SDK. Install the framework package separately, then import adapters from letterbook.integrations.
Pass a stable convo_id such as your chat session, thread, or conversation id when using turn-based detection. Framework run/event ids are per model call and are not used as fallbacks because they split one transcript into separate evaluations.
LangChain:
from langchain_openai import ChatOpenAI
from letterbook.integrations import create_langchain_callback_handler
handler = create_langchain_callback_handler(
user_id="user123",
model="gpt_4",
convo_id="conv789",
customer_email="customer@example.com",
)
model = ChatOpenAI(callbacks=[handler])
LlamaIndex:
from llama_index.core import Settings
from llama_index.core.callbacks import CallbackManager
from letterbook.integrations import create_llamaindex_callback_handler
handler = create_llamaindex_callback_handler(
user_id="user123",
model="gpt_4",
convo_id="conv789",
customer_email="customer@example.com",
)
Settings.callback_manager = CallbackManager([handler])
Metadata
Release files for letterbook-ai-chat 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| letterbook_ai_chat-1.1.0.tar.gz | 10.6 kB | Without provenance | Details for letterbook_ai_chat-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| letterbook_ai_chat-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for letterbook_ai_chat-1.1.0-py3-none-any.whl |
Total release size: 24.2 kB
Release files / letterbook_ai_chat-1.1.0.tar.gz
| Download URL | letterbook_ai_chat-1.1.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07ada32f43735815f766175bba9b0b6ab3972a4db7a55e76169b87a03b935a3a
|
|
BLAKE2b-256 checksum How to use checksums |
d08593c8c93984da3787c9404a904baf4cdd854c86d7b5b75ba2b5727e34c7d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Release files / letterbook_ai_chat-1.1.0-py3-none-any.whl
| Download URL | letterbook_ai_chat-1.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a558a6322316819168547e0693b4424808e075d799cff4c65d3d276783e6ca98
|
|
BLAKE2b-256 checksum How to use checksums |
fabd5ec953d3ea1a459075827bc8763c7144c2f54e97afd8d31044e9fe5d2c91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Security for letterbook-ai-chat 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.