The Raindrop SDK allows you to track user events and AI interactions in your app. This documentation provides a brief overview of how to use the Python SDK.
track_ai
function. It takes the following parameters:
user_id
(str): The unique identifier of the user.event
(str): The name of the AI event you want to track.event_id
(Optional[str]): A unique identifier for this specific event. If not provided, a UUID will be generated.model
(Optional[str]): The name of the AI model used.input
(Optional[str]): The input provided to the AI model. (Either this or output
is required if AI data is logged)output
(Optional[str]): The output generated by the AI. (Either this or input
is required if AI data is logged)convo_id
(Optional[str]): The conversation ID associated with the interaction. Helpful in AI apps with multiple conversations per user (e.g. ChatGPT).properties
(Optional[Dict[str, Any]]): Additional properties associated with the AI event.timestamp
(Optional[str]): An ISO 8601 formatted timestamp for the event. If not provided, the SDK generates a UTC timestamp.attachments
(Optional[List[Attachment]]): A list of attachments associated with the event. See the Attachments section below.type
(string): The type of attachment. Can be “code”, “text”, “image”, or “iframe”.name
(optional string): A name for the attachment. value
(string): The content or URL of the attachment.role
(string): Either “input” or “output”, indicating whether the attachment is part of the user input or AI output. language
(optional string): For code attachments, specifies the programming language.identify
function. It takes the following parameters:
user_id
(str): The unique identifier of the user.traits
(Dict[str, Union[str, int, bool, float]]): The traits associated with the user.begin()
and Interaction
object to send partial updates.
begin()
Interaction
helper object.
user_id
(str): The user’s identifier.event
(str): The name of the event.event_id
(Optional[str]): A unique ID for the event. If not provided, one is generated.properties
(Optional[Dict[str, Any]]): Initial properties for the event.input
(Optional[str]): Initial input for the AI.attachments
(Optional[List[Attachment]]): Initial attachments.convo_id
(Optional[str]): Conversation ID.resume_interaction()
event_id
for an ongoing interaction, you can get an Interaction
object:
Interaction
Object MethodsInteraction
object has the following methods to update the event:
interaction.set_input(text: str)
: Updates the AI input.interaction.add_attachments(attachments: List[Attachment])
: Adds more attachments.interaction.set_properties(props: Dict[str, Any])
: Merges new properties with existing ones.interaction.set_property(key: str, value: str)
: Convenience for setting a single property.interaction.finish(output: Optional[str] = None, **extra)
: Marks the interaction as complete.
output
: The final AI output.**extra
: Any other top-level TrackAIEvent
fields to update (e.g., properties
, attachments
).finish()
is called.
Example usage:
track_signal
function:
event_id
(str): The ID of the event to attach the signal to.name
(str): Name of the signal (e.g., “thumbs_up”, “copied_code”).signal_type
(Literal[“default”, “feedback”, “edit”]): Type of signal. Defaults to "default"
.
"feedback"
signals, a "comment"
string must be included in the properties
."edit"
signals, an "after"
string (representing the content after edit) must be included in the properties
.timestamp
(Optional[str]): ISO 8601 formatted timestamp. Defaults to current UTC time.properties
(Optional[Dict[str, Any]]): Additional properties for the signal.attachment_id
(Optional[str]): ID of a specific attachment within the original event to associate this signal with.comment
(Optional[str]): Convenience parameter for feedback signals. If provided, it’s added to properties
as {"comment": "your comment"}
.after
(Optional[str]): Convenience parameter for edit signals. If provided, it’s added to properties
as {"after": "new content"}
.max_queue_size
: Maximum number of events to store in the buffer (default: 10_000)upload_size
: Number of events to send in a single API request (default: 10)upload_interval
: Time interval in seconds between automatic flushes (default: 1.0) You can modify these parameters if needed:set_debug_logs
function:
tracing_enabled=True
to raindrop.init(...)
.@raindrop.interaction
.@raindrop.tool
.begin(...)
, and finishes it later via resume_interaction()
.
@raindrop.interaction()
decorator (Beta)@raindrop.interaction("name")
decorator to ensure a tracing context exists, which allows resume_interaction()
to find the current Interaction without passing an event_id
:
resume_interaction()
resolves the current Interaction by reading the active tracing context (current span). It will only find an existing Interaction when called under the same traced execution that called begin(...)
(for example, inside a function decorated with @raindrop.task
, @raindrop.tool
, or @raindrop.interaction
).resume_interaction(event_id="...")
.event_id
is available, a new Interaction
instance will be created.