Architecture
Instead of calling provider APIs directly (OpenAI, Bedrock, Gemini, etc.), all LLM requests go through a single gateway:Provider Coverage
Every model is called through the same unified request, tool-calling, and streaming interface, whichever provider serves it. Alongside the OpenAI, Anthropic (Bedrock), and Gemini families, the gateway also routes to the DeepSeek (including DeepSeek R1), Qwen 3 (including the vision-capableqwen3-vl family), and Z.ai GLM model families on Amazon Bedrock.
Not every model family supports every feature, and the gateway validates per-family limitations up front with a clear error instead of surfacing a raw provider failure mid-request. For example, a tool-calling request against DeepSeek R1 — which does not support tool use — fails immediately with a descriptive error before the request ever reaches the provider.
Capability Flags
The gateway’s model catalog can declare per-model capability flags, surfaced in each model’smetadata on the model list (GET /api/ai/models), so you can pick a model by what it actually supports:
The flags are tri-state:
true, false, or omitted entirely when a capability has not been declared for that model.Streaming Errors
If a streaming call fails after the stream has started, the failure arrives as a structured error event in the stream — using the same error taxonomy as non-streaming calls — rather than as error text spliced into the model’s reply. The stream still terminates with the normal[DONE] sentinel, so consumers that only watch for the sentinel exit cleanly.
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:
