LLM Clients API Reference
Maticlib provides a unified interface for multiple LLM providers. All clients inherit from BaseLLMClient and support both synchronous and asynchronous completion.
OpenAI Client
Using the modern OpenAI Responses API.
maticlib.llm.openai.client.OpenAIClient
OpenAIClient(
model="gpt-4o-mini",
system_instruct=None,
api_key=None,
verbose=True,
return_raw=False,
)
Bases: BaseLLMClient
Client for interacting with OpenAI models via the Responses API.
Inherits from BaseLLMClient and implements OpenAI-specific message
formatting and response parsing. Supports all current GPT and o-series
models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The OpenAI model to use. Defaults to |
'gpt-4o-mini'
|
system_instruct
|
str | SystemMessage
|
An optional system / developer prompt prepended to every request. |
None
|
api_key
|
str
|
Your OpenAI API key. Falls back to the
|
None
|
verbose
|
bool
|
If |
True
|
return_raw
|
bool
|
If |
False
|
Source code in maticlib/llm/openai/client.py
async_complete
async
Sends an asynchronous generation request to the OpenAI Responses API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | list
|
The user prompt as a plain string, or a conversation history as a list of message objects / dicts. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/openai/client.py
complete
Sends a synchronous generation request to the OpenAI Responses API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | list
|
The user prompt as a plain string, or a conversation history as a list of message objects / dicts. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/openai/client.py
get_text_response
Extracts the primary text content from an OpenAI response.
This is a convenience helper so callers do not need to traverse
the output list manually.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
OpenAIResponse | dict
|
The response returned by
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The extracted text string, or an empty string if no text was found. |
Source code in maticlib/llm/openai/client.py
Mistral Client
Using the native Mistral AI Chat Completions API.
maticlib.llm.mistral.client.MistralClient
MistralClient(
model="mistral-medium-latest",
system_instruct=None,
api_key=None,
verbose=True,
return_raw=False,
)
Bases: BaseLLMClient
Client for interacting with Mistral AI models.
Inherits from BaseLLMClient and implements Mistral-specific message formatting and response parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The name of the Mistral model to use. Defaults to "mistral-medium-latest". |
'mistral-medium-latest'
|
system_instruct
|
str | SystemMessage
|
Default instructions to prepend to all conversations. |
None
|
api_key
|
str
|
Your Mistral AI API key. Defaults to MISTRAL_API_KEY environment variable. |
None
|
verbose
|
bool
|
If True, prints status messages to console. |
True
|
return_raw
|
bool
|
If True, returns the raw dict response instead of a MistralResponse model. |
False
|
Source code in maticlib/llm/mistral/client.py
async_complete
async
Sends an asynchronous chat completion request to Mistral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | list
|
The user prompt or conversation history. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/mistral/client.py
complete
Sends a synchronous chat completion request to Mistral.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | list
|
The user prompt or conversation history. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/mistral/client.py
get_text_response
Extracts the primary text content from a Mistral response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
MistralResponse | dict
|
The response to extract from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The extracted text string. |
Source code in maticlib/llm/mistral/client.py
Google GenAI Client
Using the Google Gemini Developer API.
maticlib.llm.google_genai.client.GoogleGenAIClient
GoogleGenAIClient(
model="gemini-2.5-flash-lite",
system_instruct=None,
api_key=None,
thinking_budget=0,
verbose=True,
return_raw=False,
)
Bases: BaseLLMClient
Client for interacting with Google's Generative AI (Gemini) models.
Inherits from BaseLLMClient and implements Gemini-specific message formatting and response parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The name of the Gemini model to use. Defaults to "gemini-2.5-flash". |
'gemini-2.5-flash-lite'
|
system_instruct
|
str | SystemMessage
|
Default instructions to prepend to all conversations. |
None
|
api_key
|
str
|
Your Google AI API key. |
None
|
thinking_budget
|
int
|
Optional token budget for model reasoning/thinking. |
0
|
verbose
|
bool
|
If True, prints status messages to console. |
True
|
return_raw
|
bool
|
If True, returns the raw dict response instead of a GeminiResponse model. |
False
|
Source code in maticlib/llm/google_genai/client.py
async_complete
async
Sends an asynchronous generation request to Gemini.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
The text input to send to the model. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/google_genai/client.py
complete
Sends a synchronous generation request to Gemini.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | list
|
The user prompt or conversation history. |
required |
response_model
|
Type[BaseModel]
|
A Pydantic model to parse the output into. |
None
|
tools
|
list
|
A list of tool functions decorated with @tool. |
None
|
Source code in maticlib/llm/google_genai/client.py
get_text_response
Extracts the primary text content from a Gemini response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
GeminiResponse | dict
|
The response to extract from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The extracted text string. |
Source code in maticlib/llm/google_genai/client.py
Response Models
Standardized models used to ensure consistency across providers.
OpenAI Response (OpenAIResponse)
All OpenAI clients return an OpenAIResponse containing both general and provider-specific fields.
Common (Inherited) Fields
| Field | Type | Source Mapping |
|---|---|---|
content |
str |
Concatenated text from all output_text parts. |
content_parts |
List[ContentPart] |
Exactly one ContentPart per output_text chunk. |
prompt_tokens |
int |
Mapped from usage.input_tokens. |
completion_tokens |
int |
Mapped from usage.output_tokens. |
total_tokens |
int |
Mapped from usage.total_tokens. |
finish_reason |
str |
Mapped from the first output item's status. |
response_id |
str |
Mapped from top-level id. |
raw_response |
Dict[str, Any] |
The original, full JSON response dictionary. |
OpenAI-Specific Fields
| Field | Type | Description |
|---|---|---|
id |
str |
Response ID (prefixed with resp_). |
object |
str |
Always "response". |
created_at |
int |
Unix timestamp of creation. |
status |
str |
Response-level status (e.g. completed, failed). |
output |
List[OpenAIOutputMessage] |
Ordered list of output items returned by the API. |
usage |
OpenAIUsage |
Detailed token-usage breakdown. |
model_version |
str |
Model version string echoed back by OpenAI. |
OpenAI-Specific Properties
| Property | Type | Description |
|---|---|---|
cached_tokens |
int |
Input tokens served from the prompt cache. A non-zero value means the model reused previously computed KV-cache entries. |
reasoning_tokens |
int \| None |
Tokens used for internal model reasoning (o-series models only). Returns None for standard models. |
timestamp |
datetime |
Converts the created_at Unix timestamp into a datetime object. |
maticlib.llm.openai.openai_classes.OpenAIResponse
Bases: LLMResponseBase
OpenAI Responses API response (/v1/responses).
Maps the raw JSON payload onto the shared LLMResponseBase interface
so callers can use response.content and response.content_parts
the same way they would with MistralResponse or GeminiResponse.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Concatenated text from all output_text parts. |
content_parts |
List[ContentPart]
|
One ContentPart per output_text chunk. |
prompt_tokens |
int
|
Mapped from usage.input_tokens. |
completion_tokens |
int
|
Mapped from usage.output_tokens. |
total_tokens |
int
|
Mapped from usage.total_tokens. |
finish_reason |
str
|
Mapped from first output item's status. |
response_id |
str
|
Mapped from top-level id. |
raw_response |
Dict[str, Any]
|
Original JSON dict. |
id |
str
|
Response ID (resp_...). |
object |
str
|
Always "response". |
created_at |
int
|
Unix timestamp of creation. |
status |
str
|
Response-level status (completed, failed, ...). |
output |
List[OpenAIOutputMessage]
|
Ordered list of output items. |
usage |
OpenAIUsage
|
Detailed token-usage breakdown. |
model_version |
str
|
Model string echoed back by OpenAI. |
cached_tokens |
Optional[int]
|
Input tokens served from the prompt cache. |
reasoning_tokens |
Optional[int]
|
Tokens used for internal model reasoning (o-series models only). |
timestamp |
datetime
|
Converts the created_at Unix timestamp into a datetime object. |
Source code in maticlib/llm/openai/openai_classes.py
cached_tokens
property
Input tokens served from the prompt cache.
A non-zero value means the model reused previously computed KV-cache entries, which are billed at a reduced rate.
reasoning_tokens
property
Tokens used for internal model reasoning (o-series models only).
Returns None for standard GPT models that do not expose
reasoning-token counts.
Mistral Response (MistralResponse)
maticlib.llm.mistral.mistral_classes.MistralResponse
Bases: LLMResponseBase
Mistral-specific response structure. Supports both text-only and multimodal (Pixtral) models. Inherits from LLMResponseBase and adds Mistral-specific fields.
Mistral-Specific Properties
timestamp
Convert Unix timestamp to datetime.
maticlib.llm.mistral.mistral_classes.MistralResponse
Bases: LLMResponseBase
Mistral-specific response structure.
Supports both text-only and multimodal (Pixtral) models. Inherits from LLMResponseBase and adds Mistral-specific fields.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the Mistral response. |
created |
int
|
Unix timestamp of creation. |
object |
str
|
Object type (e.g., 'chat.completion'). |
choices |
List[MistralChoice]
|
List of completion choices. |
timestamp |
datetime
|
Convert Unix timestamp to datetime object. |
Source code in maticlib/llm/mistral/mistral_classes.py
Gemini Response (GeminiResponse)
maticlib.llm.google_genai.gemini_classes.GeminiResponse
Bases: LLMResponseBase
Gemini-specific response structure. Supports multimodal inputs (text, image, audio, video) and outputs. Inherits from LLMResponseBase and adds Gemini-specific fields.
Gemini-Specific Properties
cached_token_count
Get cached content token count (Gemini context caching).
thoughts_token_count
Get the thoughts token count if available (Gemini-specific).
maticlib.llm.google_genai.gemini_classes.GeminiResponse
Bases: LLMResponseBase
Gemini-specific response structure.
Supports multimodal inputs (text, image, audio, video) and outputs. Inherits from LLMResponseBase and adds Gemini-specific fields.
Attributes:
| Name | Type | Description |
|---|---|---|
responseId |
str
|
Unique identifier for the Gemini response. |
modelVersion |
str
|
Gemini model version. |
candidates |
List[GeminiCandidate]
|
List of candidate responses. |
usageMetadata |
GeminiUsageMetadata
|
Token usage metadata. |
cached_token_count |
Optional[int]
|
Get cached content token count (Gemini context caching). |
thoughts_token_count |
Optional[int]
|
Get the thoughts token count if available (Gemini-specific). |
Source code in maticlib/llm/google_genai/gemini_classes.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |