Architecture
Instead of calling provider APIs directly (OpenAI, Bedrock, Gemini, etc.), all LLM requests go through a single gateway:Quick Start
ModelManager
ModelManager is a singleton that discovers available models from the platform at runtime. On first use, it queries the platform’s cloud-models API and creates a GatewayModelProvider for each model.
Getting Models
Environment Variables
When running inside a Kodexa module execution,
KODEXA_URL and KODEXA_ACCESS_TOKEN are automatically set by the platform. You do not need to configure them manually.ChatMessage
Represents a message in a conversation with an LLM.Fields
Invoking Models
Basic Invocation
invoke() sends messages and returns the response synchronously.
Returns:
Tuple[str, Optional[str], LLMUsageMetrics]
str— The response textOptional[str]— Thinking output (if thinking mode enabled and supported)LLMUsageMetrics— Token usage and timing
Async Invocation
Async invocation requires the
httpx package. Install it with: pip install httpxStreaming
stream_invoke() yields text chunks as they arrive from the model, useful for real-time display.
Thinking Mode
Some models (Claude 3.7+, Gemini 2.5+) support extended thinking, where the model shows its reasoning process.Function Calling / Structured Output
Useinvoke_function() to extract structured data using a JSON schema. The model is instructed to call a function with arguments matching your schema.
Multimodal Input
Send images alongside text for visual document analysis:PDF Documents
Setmedia_type="application/pdf" to send a PDF as a native document, letting the model read the whole file—text and layout—without rasterizing it to page images first.
LLMUsageMetrics
Every invocation returns usage metrics for cost tracking and monitoring.Cost Tracking
Token usage is automatically recorded in the platform’s model interaction system. Use thenote parameter to label interactions for billing visibility:
