SketricGen Python SDK
Python SDK for the SketricGen Chat Server API. Build AI-powered workflows, chat applications, and document analysis tools.Requirements
- Python 3.9+
- Dependencies:
httpx>=0.25.0,pydantic>=2.0.0,typing-extensions>=4.0.0
Installation
Quick Start
Features
- Run Workflows: Execute chat/workflow requests with AI agents
- Streaming: Real-time streaming responses using Server-Sent Events
- File Attachments: Attach images and PDFs to workflows
- Async & Sync: Both async and synchronous API support
- Type Safety: Full type hints for IDE support
- Error Handling: Comprehensive custom exception types
Client Reference
SketricGenClient
The main client for interacting with the SketricGen API.Constructor
From Environment Variables
| Environment Variable | Default | Description |
|---|---|---|
SKETRICGEN_API_KEY | required | Your API key |
SKETRICGEN_TIMEOUT | 300 | Request timeout in seconds |
SKETRICGEN_UPLOAD_TIMEOUT | 300 | Upload timeout for large files |
SKETRICGEN_MAX_RETRIES | 3 | Maximum retry attempts |
run_workflow()
Execute a workflow/chat request (async).ChatResponse if stream=False, AsyncIterator[StreamEvent] if stream=True
Example: Non-Streaming
Example: Streaming
run_workflow_sync()
Synchronous version ofrun_workflow().
ChatResponse if stream=False, Iterator[StreamEvent] if stream=True
Example
Response Models
ChatResponse
Response from a non-streaming workflow request.| Field | Type | Description |
|---|---|---|
agent_id | str | Workflow/Agent ID |
user_id | str | User identifier |
conversation_id | str | Conversation ID for follow-up messages |
response | str | The assistant’s response text |
owner | str | Owner of the agent |
error | bool | Error flag (default: False) |
StreamEvent
Individual event from a streaming response.| Field | Type | Description |
|---|---|---|
event_type | str | Type of the SSE event |
data | str | JSON string containing event data |
id | str | None | Optional event ID |
Streaming Events
The streaming API uses the AG-UI Protocol. Parse thedata field as JSON to access event details.
Event Types
| Event Type | Description | Key Fields |
|---|---|---|
RUN_STARTED | Workflow execution started | thread_id, run_id |
TEXT_MESSAGE_START | Assistant message started | message_id, role |
TEXT_MESSAGE_CONTENT | Text chunk received | message_id, delta |
TEXT_MESSAGE_END | Assistant message completed | message_id |
TOOL_CALL_START | Tool/function call started | tool_call_id, tool_call_name |
TOOL_CALL_END | Tool/function call completed | tool_call_id |
RUN_FINISHED | Workflow completed | thread_id, run_id |
RUN_ERROR | Workflow error occurred | message |
CUSTOM | Custom event | varies |
Complete Streaming Example
File Attachments
Attach files to workflows for document analysis and image understanding.Supported File Types
| Type | MIME Types | Max Size |
|---|---|---|
| Images | image/jpeg, image/png, image/webp, image/gif | 20 MB |
| Documents | application/pdf | 20 MB |

