Skip to main content
View module source on GitHub

MaximAnthropicMessages

Maxim-enhanced Anthropic Messages client. This class extends the Anthropic Messages resource to integrate with Maxim’s logging and monitoring capabilities. It automatically tracks message creation, both streaming and non-streaming, and logs them through the Maxim platform. The class handles trace management, generation logging, and error handling while maintaining compatibility with the original Anthropic Messages API. Attributes:

__init__

Initialize the Maxim Anthropic Messages client. Arguments: logging message interactions.

create_non_stream

Create a non-streaming message with Maxim logging. This method handles non-streaming message creation while automatically logging the interaction through Maxim. It manages trace creation, generation tracking, and error handling. Arguments: Special headers:
  • x-maxim-trace-id: Optional trace ID for associating with existing trace.
  • x-maxim-generation-name: Optional name for the generation.
Returns: Notes: If logging fails, the method will still return the API response but will log a warning message.

create_stream

Create a streaming message with Maxim logging. This method handles streaming message creation while automatically logging the interaction through Maxim. It manages trace creation, generation tracking, and processes streaming events. Arguments: Special headers:
  • x-maxim-trace-id: Optional trace ID for associating with existing trace.
  • x-maxim-generation-name: Optional name for the generation.
Returns: handles logging of streaming events. Notes: The method returns a StreamWrapper that automatically processes stream chunks and logs the final result when the stream ends.

create

Create a message with automatic streaming detection and Maxim logging. This is the main entry point for message creation. It automatically detects whether streaming is requested and routes to the appropriate handler while ensuring all interactions are logged through Maxim. Arguments: Returns: Notes: The method automatically detects streaming mode via the ‘stream’ parameter in kwargs and routes accordingly.

stream

Create a streaming message with Maxim logging. This method is a direct alias for create_stream, providing compatibility with the standard Anthropic Messages API while adding Maxim logging. Arguments: Returns: