MoxnClient is your main entry point for interacting with the Moxn platform. It handles authentication, fetching prompts, creating sessions, managing telemetry, and code generation.
Usage
MOXN_API_KEY from your environment.
Fetching Content
get_prompt
Fetch a prompt template with optional caching.| Name | Type | Description |
|---|---|---|
prompt_id | UUID | str | The prompt’s anchor ID |
branch_name | str | None | Branch name (mutually exclusive with commit_id) |
commit_id | str | None | Commit ID for immutable access (mutually exclusive with branch_name) |
PromptTemplate
Caching Behavior:
- Commit access: Cached indefinitely (immutable)
- Branch access: Always fetches latest (mutable)
get_task
Fetch an entire task with all its prompts and schemas.| Name | Type | Description |
|---|---|---|
task_id | str | The task’s anchor ID |
branch_name | str | None | Branch name |
commit_id | str | None | Commit ID |
Task
get_branch_head
Get the head commit for a branch. Useful for determining deployment versions.BranchHeadResponse with:
effective_commit_id: The commit ID to usehas_uncommitted_changes: Whether there are pending changeslast_committed_at: Timestamp of last commit
Creating Sessions
create_prompt_session
Create a new prompt session by fetching a prompt and combining it with session data.| Name | Type | Description |
|---|---|---|
prompt_id | str | The prompt’s anchor ID |
branch_name | str | None | Branch name |
commit_id | str | None | Commit ID |
session_data | RenderableModel | None | Pydantic model for variable substitution |
PromptSession
prompt_session_from_session_data
Create a session using the prompt ID embedded in the session data’s metadata.prompt_id from session_data.moxn_schema_metadata, so you don’t need to specify it separately.
Telemetry & Spans
span
Create a span for tracing and observability.| Name | Type | Description |
|---|---|---|
prompt_session | PromptSession | The session for this span |
name | str | None | Span name (defaults to prompt name) |
metadata | dict | None | Searchable attributes (customer_id, request_id, etc.) |
parent_context | SpanContext | None | Explicit parent for async patterns |
trace_context | TraceContext | None | For distributed tracing |
AsyncGenerator[Span, None]
span_from_carrier
Create a span from a trace carrier for distributed tracing.extract_context
Extract the current span context for propagation across services.MoxnTraceCarrier if there’s an active span, None otherwise.
log_telemetry_event
Log an LLM event to the current span.log_telemetry_event_from_response
Convenience method to parse a provider response and log it in one call.| Name | Type | Description |
|---|---|---|
prompt_session | PromptSession | The session used for the request |
response | Provider response | Raw response from the LLM provider |
provider | Provider | The provider enum value |
flush
Await in-flight telemetry logs. Call this at process exit or Lambda return.Code Generation
generate_task_models
Generate Pydantic models from all schemas in a task.| Name | Type | Description |
|---|---|---|
task_id | str | UUID | The task ID |
branch_name | str | None | Branch name (defaults to “main”) |
commit_id | str | None | Commit ID |
output_dir | Path | str | None | Directory to write generated code |
DatamodelCodegenResponse with generated code