MoxnClient
TheMoxnClient is your primary interface to the Moxn API. Always use it as an async context manager:
- Creates and manages HTTP connections
- Starts the telemetry dispatcher
- Ensures proper cleanup on exit
- Flushes pending telemetry events
Configuration
The client reads configuration from environment variables:| Variable | Description | Default |
|---|---|---|
MOXN_API_KEY | Your API key (required) | - |
MOXN_BASE_URL | API base URL | https://api.moxn.dev |
MOXN_TIMEOUT | Request timeout (seconds) | 30 |
Fetching Prompts
get_prompt()
Fetch a single prompt by ID:prompt_id: UUID or string ID of the promptbranch_name: Branch to fetch from (mutually exclusive withcommit_id)commit_id: Specific commit to fetch (mutually exclusive withbranch_name)
PromptTemplate object
get_task()
Fetch an entire task with all its prompts:task_id: UUID or string ID of the taskbranch_name: Branch to fetch fromcommit_id: Specific commit to fetch
Task object containing all prompts and schemas
Access Patterns
Branch Access (Development)
Usebranch_name during development to always get the latest version:
- Returns the latest state including uncommitted changes
- Not cached (always fetches fresh)
- May change between calls
- Includes working state modifications
Commit Access (Production)
Usecommit_id in production for immutable, reproducible prompts:
- Returns an immutable snapshot
- Cached indefinitely (commits never change)
- Guaranteed reproducibility
- No working state, only committed data
Getting the Latest Commit
To get the latest committed state (without uncommitted changes), use a two-step pattern:Caching Behavior
The SDK uses an in-memory cache for commit-based access:- Commit-based fetches are cached (commits are immutable)
- Branch-based fetches always go to the API (branches change)
- Cache is per-client instance
- Cache is in-memory only (not persisted)
PromptTemplate Structure
When you fetch a prompt, you get aPromptTemplate object:
Accessing Messages
Messages contain blocks
Messages use a 2D array structure for content blocks:TextContent: Plain textVariable: Template variablesImageContentFromSource: ImagesPDFContentFromSource: PDF documentsToolCall/ToolResult: Function calling