Documentation Index
Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
View module source on GitHub
Configuration class for Maxim Logger.
This class holds the configuration settings for the Logger, including
the logger ID, auto-flush setting, and flush interval.
Attributes:
| Name | Type | Description |
|---|
id | str | The unique identifier for the logger. |
auto_flush | bool | Whether to automatically flush logs. Defaults to True. |
flush_interval | int | The interval (in seconds) at which to flush logs when auto_flush is True. Defaults to 10 seconds. |
@deprecated(
"This class will be removed in a future version. Use LoggerConfigDict instead."
)
class LoggerConfig()
Configuration class for Maxim Logger.
This class holds the configuration settings for the Logger, including
the logger ID, auto-flush setting, and flush interval.
Attributes:
| Name | Type | Description |
|---|
id | str | The unique identifier for the logger. |
auto_flush | bool | Whether to automatically flush logs. |
flush_interval | int | The interval (in seconds) at which to flush logs when auto_flush is True. |
A class representing a logger for the Maxim SDK.
This logger provides methods for creating sessions, traces, and various logging components
such as spans, generations, retrievals, and tool calls. It uses a LogWriter to handle the
actual logging operations.
Attributes:
| Name | Type | Description |
|---|
_id | str | The unique identifier for this logger instance. |
raise_exceptions | bool | Whether to raise exceptions during logging operations. |
is_debug | bool | Whether debug logging is enabled. |
writer | LogWriter | The LogWriter instance used for actual logging operations. |
__init__
def __init__(config: LoggerConfigDict,
api_key: str,
base_url: str,
is_debug=False,
raise_exceptions=False) -> None
Initializes the logger with the given configuration.
Arguments:
| Name | Type | Description |
|---|
config | LoggerConfig | The configuration for the logger. |
api_key | str | The API key for the logger. |
base_url | str | The base URL for the logger. |
is_debug | bool, optional | Whether to enable debug logging. Defaults to False. |
raise_exceptions | bool, optional | Whether to raise exceptions. Defaults to False. |
session
def session(config: Union[SessionConfig, SessionConfigDict]) -> Session
Creates a new session with the given configuration.
Arguments:
| Name | Type | Description |
|---|
config | SessionConfig | The configuration for the new session. |
Returns:
| Name | Description |
|---|
[Session](/sdk/python/references/logger/components/session) | The newly created session. |
trace
def trace(config: Union[TraceConfig, TraceConfigDict]) -> Trace
Creates a new trace with the given configuration.
Arguments:
| Name | Type | Description |
|---|
config | TraceConfig | The configuration for the new trace. |
Returns:
| Name | Description |
|---|
[Trace](/sdk/python/references/logger/components/trace) | The newly created trace. |
session_add_tag
def session_add_tag(session_id: str, key: str, value: str)
Adds a tag to the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
key | str | The key of the tag. |
value | str | The value of the tag. |
session_end
def session_end(session_id: str)
Ends the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
session_event
def session_event(session_id: str, event_id: str, event: str, data: Any)
Adds an event to the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
event_id | str | The ID of the event. |
event | str | The name of the event. |
data | Any | The data associated with the event. |
session_feedback
@deprecated(
"This method will be removed in a future version. Use session_add_feedback instead."
)
def session_feedback(session_id: str, feedback: Union[Feedback, FeedbackDict])
Adds a feedback to the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
feedback | Feedback | The feedback to add. |
session_add_attachment
def session_add_attachment(session_id: str,
attachment: Union[FileAttachment,
FileDataAttachment,
UrlAttachment])
Adds an attachment to the session.
session_add_feedback
def session_add_feedback(session_id: str, feedback: FeedbackDict)
Adds a feedback to the session.
session_trace
@deprecated(
"This method will be removed in a future version. Use session_add_trace instead."
)
def session_trace(session_id: str, config: TraceConfig) -> Trace
Adds a trace to the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
config | TraceConfig | The configuration for the trace. |
Returns:
| Name | Description |
|---|
[Trace](/sdk/python/references/logger/components/trace) | The newly created trace. |
session_add_trace
def session_add_trace(session_id: str,
config: Union[TraceConfig, TraceConfigDict]) -> Trace
Adds a trace to the session.
Arguments:
| Name | Type | Description |
|---|
session_id | str | The ID of the session. |
config | TraceConfig | The configuration for the trace. |
Returns:
| Name | Description |
|---|
[Trace](/sdk/python/references/logger/components/trace) | The newly created trace. |
trace_generation
@deprecated(
"This method will be removed in a future version. Use trace_add_generation instead."
)
def trace_generation(trace_id: str, config: GenerationConfig) -> Generation
Adds a generation to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | GenerationConfig | The configuration for the generation. |
Returns:
| Name | Description |
|---|
[Generation](/sdk/python/references/logger/components/generation) | The newly created generation. |
trace_add_generation
def trace_add_generation(
trace_id: str, config: Union[GenerationConfig,
GenerationConfigDict]) -> Generation
Adds a generation to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | GenerationConfig | The configuration for the generation. |
Returns:
| Name | Description |
|---|
[Generation](/sdk/python/references/logger/components/generation) | The newly created generation. |
trace_retrieval
@deprecated(
"This method will be removed in a future version. Use trace_add_retrieval instead."
)
def trace_retrieval(
trace_id: str, config: Union[RetrievalConfig,
RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | RetrievalConfig | The configuration for the retrieval. |
Returns:
| Name | Description |
|---|
[Retrieval](/sdk/python/references/logger/components/retrieval) | The newly created retrieval. |
trace_add_retrieval
def trace_add_retrieval(
trace_id: str, config: Union[RetrievalConfig,
RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | RetrievalConfig | The configuration for the retrieval. |
Returns:
| Name | Description |
|---|
[Retrieval](/sdk/python/references/logger/components/retrieval) | The newly created retrieval. |
trace_span
@deprecated(
"This method will be removed in a future version. Use trace_add_span instead."
)
def trace_span(trace_id: str, config: Union[SpanConfig,
SpanConfigDict]) -> Span
Adds a span to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | SpanConfig | The configuration for the span. |
Returns:
| Name | Description |
|---|
[Span](/sdk/python/references/logger/components/span) | The newly created span. |
trace_add_span
def trace_add_span(trace_id: str, config: Union[SpanConfig,
SpanConfigDict]) -> Span
Adds a span to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | SpanConfig | The configuration for the span. |
Returns:
| Name | Description |
|---|
[Span](/sdk/python/references/logger/components/span) | The newly created span. |
trace_add_error
def trace_add_error(trace_id: str, config: ErrorConfig) -> Error
Adds an error to the trace.
trace_add_tag
def trace_add_tag(trace_id: str, key: str, value: str)
Adds a tag to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
key | str | The key of the tag. |
value | str | The value of the tag. |
def trace_add_tool_call(
trace_id: str, config: Union[ToolCallConfig,
ToolCallConfigDict]) -> ToolCall
Adds a tool call to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
config | ToolCallConfig | The configuration for the tool call. |
Returns:
| Name | Description |
|---|
[ToolCall](/sdk/python/references/models/prompt) | The newly created tool call. |
trace_event
@deprecated(
"This method will be removed in a future version. Use trace_add_event instead."
)
def trace_event(trace_id: str,
event_id: str,
event: str,
tags: Optional[Dict[str, str]] = None,
metadata: Optional[Dict[str, Any]] = None)
Adds an event to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
event_id | str | The ID of the event. |
event | str | The name of the event. |
tags | Optional[Dict[str, str]] | The tags associated with the event. |
trace_add_event
def trace_add_event(trace_id: str,
event_id: str,
event: str,
tags: Optional[Dict[str, str]] = None,
metadata: Optional[Dict[str, Any]] = None)
Adds an event to the trace.
def trace_set_input(trace_id: str, input: str)
Sets the input for the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
input | str | The input for the trace. |
trace_set_output
def trace_set_output(trace_id: str, output: str)
Sets the output for the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
output | str | The output for the trace. |
trace_feedback
@deprecated(
"This method will be removed in a future version. Use trace_add_feedback instead."
)
def trace_feedback(trace_id: str, feedback: Feedback)
Adds a feedback to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
feedback | Feedback | The feedback to add. |
trace_add_feedback
def trace_add_feedback(trace_id: str, feedback: FeedbackDict)
Adds a feedback to the trace.
def trace_add_metadata(trace_id: str, metadata: Dict[str, Any])
Adds metadata to the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
metadata | Dict[str, Any] | The metadata to add. |
trace_add_attachment
def trace_add_attachment(trace_id: str,
attachment: Union[FileAttachment, FileDataAttachment,
UrlAttachment])
Adds an attachment to the trace.
trace_end
def trace_end(trace_id: str)
Ends the trace.
Arguments:
| Name | Type | Description |
|---|
trace_id | str | The ID of the trace. |
generation_set_model
def generation_set_model(generation_id: str, model: str)
Sets the model for the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
model | str | The model for the generation. |
generation_set_provider
def generation_set_provider(generation_id: str, provider: str)
Sets the provider for the generation.
generation_add_message
def generation_add_message(generation_id: str,
message: GenerationRequestMessage)
Adds a message to the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
message | Any | The OpenAI chat message to add. |
generation_set_model_parameters
def generation_set_model_parameters(generation_id: str,
model_parameters: Dict[str, Any])
Sets the model parameters for the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
model_parameters | dict | The model parameters for the generation. |
generation_result
def generation_result(generation_id: str, result: Any)
Sets the result for the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
result | Any | The result for the generation. |
generation_add_attachment
def generation_add_attachment(generation_id: str,
attachment: Union[FileAttachment,
FileDataAttachment,
UrlAttachment])
Adds an attachment to the generation.
generation_end
def generation_end(generation_id: str)
Ends the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
generation_error
def generation_error(generation_id: str, error: GenerationError)
Sets the error for the generation.
Arguments:
| Name | Type | Description |
|---|
generation_id | str | The ID of the generation. |
error | GenerationError | The error for the generation. |
span_generation
@deprecated(
"This method will be removed in a future version. Use span_add_generation instead."
)
def span_generation(
span_id: str, config: Union[GenerationConfig,
GenerationConfigDict]) -> Generation
Adds a generation to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | GenerationConfig | The configuration for the generation. |
Returns:
| Name | Description |
|---|
[Generation](/sdk/python/references/logger/components/generation) | The newly created generation. |
span_add_generation
def span_add_generation(
span_id: str, config: Union[GenerationConfig,
GenerationConfigDict]) -> Generation
Adds a generation to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | GenerationConfig | The configuration for the generation. |
Returns:
| Name | Description |
|---|
[Generation](/sdk/python/references/logger/components/generation) | The newly created generation. |
span_add_error
def span_add_error(span_id: str, config: ErrorConfig) -> Error
Adds an error to the span.
span_retrieval
@deprecated(
"This method will be removed in a future version. Use span_add_retrieval instead."
)
def span_retrieval(
span_id: str, config: Union[RetrievalConfig,
RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | RetrievalConfig | The configuration for the retrieval. |
Returns:
| Name | Description |
|---|
[Retrieval](/sdk/python/references/logger/components/retrieval) | The newly created retrieval. |
span_add_retrieval
def span_add_retrieval(
span_id: str, config: Union[RetrievalConfig,
RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | RetrievalConfig | The configuration for the retrieval. |
Returns:
| Name | Description |
|---|
[Retrieval](/sdk/python/references/logger/components/retrieval) | The newly created retrieval. |
def span_add_tool_call(
span_id: str, config: Union[ToolCallConfig,
ToolCallConfigDict]) -> ToolCall
Adds a tool call to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | ToolCallConfig | The configuration for the tool call. |
Returns:
| Name | Description |
|---|
[ToolCall](/sdk/python/references/models/prompt) | The newly created tool call. |
span_end
def span_end(span_id: str)
Ends the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
span_add_tag
def span_add_tag(span_id: str, key: str, value: str)
Adds a tag to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
key | str | The key of the tag. |
value | str | The value of the tag. |
span_event
def span_event(span_id: str,
event_id: str,
name: str,
tags: Optional[Dict[str, str]] = None,
metadata: Optional[Dict[str, Any]] = None)
Adds an event to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
event_id | str | The ID of the event. |
name | str | The name of the event. |
tags | Optional[Dict[str, str]] | The tags associated with the event. |
def span_add_metadata(span_id: str, metadata: Dict[str, Any])
Adds metadata to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
metadata | Dict[str, Any] | The metadata to add. |
span_add_attachment
def span_add_attachment(span_id: str,
attachment: Union[FileAttachment, FileDataAttachment,
UrlAttachment])
Adds an attachment to the span.
span_span
@deprecated(
"This method will be removed in a future version. Use span_add_sub_span instead."
)
def span_span(span_id: str, config: Union[SpanConfig, SpanConfigDict]) -> Span
Adds a span to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | SpanConfig | The configuration for the sub-span. |
Returns:
| Name | Description |
|---|
[Span](/sdk/python/references/logger/components/span) | The newly created sub-span. |
span_add_sub_span
def span_add_sub_span(span_id: str, config: Union[SpanConfig,
SpanConfigDict]) -> Span
Adds a sub-span to the span.
Arguments:
| Name | Type | Description |
|---|
span_id | str | The ID of the span. |
config | SpanConfig | The configuration for the sub-span. |
Returns:
| Name | Description |
|---|
[Span](/sdk/python/references/logger/components/span) | The newly created sub-span. |
retrieval_end
def retrieval_end(retrieval_id: str)
Ends the retrieval.
Arguments:
| Name | Type | Description |
|---|
retrieval_id | str | The ID of the retrieval. |
def retrieval_input(retrieval_id: str, query: Any)
Sets the input for the retrieval.
Arguments:
| Name | Type | Description |
|---|
retrieval_id | str | The ID of the retrieval. |
query | Any | The input for the retrieval. |
retrieval_output
def retrieval_output(retrieval_id: str, docs: Any)
Sets the output for the retrieval.
Arguments:
| Name | Type | Description |
|---|
retrieval_id | str | The ID of the retrieval. |
docs | Any | The output for the retrieval. |
retrieval_add_tag
def retrieval_add_tag(retrieval_id: str, key: str, value: str)
Adds a tag to the retrieval.
Arguments:
| Name | Type | Description |
|---|
retrieval_id | str | The ID of the retrieval. |
key | str | The key of the tag. |
value | str | The value of the tag. |
retrieval_add_attachment
def retrieval_add_attachment(retrieval_id: str,
attachment: Union[FileAttachment,
FileDataAttachment,
UrlAttachment])
Adds an attachment to the retrieval.
def tool_call_update(tool_call_id: str, data: Dict[str, Any])
Updates the tool call.
Arguments:
| Name | Type | Description |
|---|
tool_call_id | str | The ID of the tool call. |
data | Dict[str, Any] | The data to update the tool call with. |
def tool_call_result(tool_call_id: str, result: Any)
Sets the result for the tool call.
Arguments:
| Name | Type | Description |
|---|
tool_call_id | str | The ID of the tool call. |
result | Any | The result for the tool call. |
def tool_call_error(tool_call_id: str, error: Union[ToolCallError,
ToolCallErrorDict])
Sets the error for the tool call.
Arguments:
| Name | Type | Description |
|---|
tool_call_id | str | The ID of the tool call. |
error | ToolCallError | The error for the tool call. |
def tool_call_add_metadata(tool_call_id: str, metadata: Dict[str, Any])
Adds metadata to the tool call.
Arguments:
| Name | Type | Description |
|---|
tool_call_id | str | The ID of the tool call. |
metadata | Dict[str, Any] | The metadata to add. |
Returns the ID of the logger.
flush
Flushes the writer.
cleanup
def cleanup(is_sync=False)
Cleans up the writer.