> ## 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.

# Message

> Message utilities for anthropic ai model integration and logging utilities.

[View module source on GitHub](https://github.com/maximhq/maxim-py/blob/main/maxim/logger/anthropic/message.py)

## [MaximAnthropicMessages](/sdk/python/references/logger/anthropic/message)

```python theme={null}
class MaximAnthropicMessages(Messages)
```

[Maxim](/sdk/python/references/maxim)-enhanced Anthropic Messages client.

This class extends the Anthropic Messages resource to integrate with [Maxim](/sdk/python/references/maxim)'s
logging and monitoring capabilities. It automatically tracks message creation,
both streaming and non-streaming, and logs them through the [Maxim](/sdk/python/references/maxim) platform.

The class handles trace management, generation logging, and error handling
while maintaining compatibility with the original Anthropic Messages API.

**Attributes**:

| Name      | Type                                             | Description                                                                          |
| --------- | ------------------------------------------------ | ------------------------------------------------------------------------------------ |
| `_logger` | *[Logger](/sdk/python/references/logger/logger)* | The [Maxim](/sdk/python/references/maxim) logger instance for tracking interactions. |

#### \_\_init\_\_

```python theme={null}
def __init__(client: Anthropic, logger: Logger)
```

Initialize the [Maxim](/sdk/python/references/maxim) Anthropic Messages client.

**Arguments**:

| Name     | Type                                             | Description                                                                |
| -------- | ------------------------------------------------ | -------------------------------------------------------------------------- |
| `client` | *Anthropic*                                      | The Anthropic client instance.                                             |
| `logger` | *[Logger](/sdk/python/references/logger/logger)* | The [Maxim](/sdk/python/references/maxim) logger instance for tracking and |

logging message interactions.

#### create\_non\_stream

```python theme={null}
def create_non_stream(*args, **kwargs) -> Any
```

Create a non-streaming message with [Maxim](/sdk/python/references/maxim) logging.

This method handles non-streaming message creation while automatically
logging the interaction through [Maxim](/sdk/python/references/maxim). It manages trace creation,
generation tracking, and error handling.

**Arguments**:

| Name       | Description                                                                                                |
| ---------- | ---------------------------------------------------------------------------------------------------------- |
| `*args`    | [Variable](/sdk/python/references/models/dataset) length argument list passed to the parent create method. |
| `**kwargs` | Arbitrary keyword arguments passed to the parent create method.                                            |

Special headers:

* x-maxim-trace-id: Optional trace ID for associating with existing trace.
* x-maxim-generation-name: Optional name for the generation.

**Returns**:

| Name  | Description                                        |
| ----- | -------------------------------------------------- |
| `Any` | The response from the Anthropic API create method. |

**Notes**:

If logging fails, the method will still return the API response
but will log a warning message.

#### create\_stream

```python theme={null}
def create_stream(*args, **kwargs) -> Any
```

Create a streaming message with [Maxim](/sdk/python/references/maxim) logging.

This method handles streaming message creation while automatically
logging the interaction through [Maxim](/sdk/python/references/maxim). It manages trace creation,
generation tracking, and processes streaming events.

**Arguments**:

| Name       | Description                                                                                                |
| ---------- | ---------------------------------------------------------------------------------------------------------- |
| `*args`    | [Variable](/sdk/python/references/models/dataset) length argument list passed to the parent stream method. |
| `**kwargs` | Arbitrary keyword arguments passed to the parent stream method.                                            |

Special headers:

* x-maxim-trace-id: Optional trace ID for associating with existing trace.
* x-maxim-generation-name: Optional name for the generation.

**Returns**:

| Name                                                                      | Description                                        |
| ------------------------------------------------------------------------- | -------------------------------------------------- |
| `[StreamWrapper](/sdk/python/references/logger/anthropic/stream_manager)` | A wrapped stream manager that processes chunks and |

handles logging of streaming events.

**Notes**:

The method returns a [StreamWrapper](/sdk/python/references/logger/anthropic/stream_manager) that automatically processes
stream chunks and logs the final result when the stream ends.

#### create

```python theme={null}
def create(*args,
           max_tokens: int,
           messages: Iterable[MessageParam],
           model: str,
           metadata: MetadataParam | NotGiven = NOT_GIVEN,
           stop_sequences: List[str] | NotGiven = NOT_GIVEN,
           system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
           temperature: float | NotGiven = NOT_GIVEN,
           tool_choice: dict | NotGiven = NOT_GIVEN,
           tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
           top_k: int | NotGiven = NOT_GIVEN,
           top_p: float | NotGiven = NOT_GIVEN,
           extra_headers: Headers | None = None,
           extra_query: Query | None = None,
           extra_body: Body | None = None,
           timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
           **kwargs) -> Any
```

Create a message with automatic streaming detection and [Maxim](/sdk/python/references/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](/sdk/python/references/maxim).

**Arguments**:

| Name             | Type                                     | Description                                                  |                                      |            |                  |
| ---------------- | ---------------------------------------- | ------------------------------------------------------------ | ------------------------------------ | ---------- | ---------------- |
| `max_tokens`     | *int*                                    | The maximum number of tokens to generate.                    |                                      |            |                  |
| `messages`       | *Iterable\[MessageParam]*                | The conversation messages.                                   |                                      |            |                  |
| `model`          | *str*                                    | The model to use for generation.                             |                                      |            |                  |
| `metadata`       | \_MetadataParam                          | NotGiven\_                                                   | Additional metadata for the request. |            |                  |
| `stop_sequences` | \_List\[str]                             | NotGiven\_                                                   | Sequences that will stop generation. |            |                  |
| `system`         | \_Union\[str, Iterable\[TextBlockParam]] | NotGiven\_                                                   | System message.                      |            |                  |
| `temperature`    | \_float                                  | NotGiven\_                                                   | Sampling temperature (0-1).          |            |                  |
| `tool_choice`    | \_dict                                   | NotGiven\_                                                   | How the model should use tools.      |            |                  |
| `tools`          | \_Iterable\[ToolParam]                   | NotGiven\_                                                   | Available tools for the model.       |            |                  |
| `top_k`          | \_int                                    | NotGiven\_                                                   | Top-k sampling parameter.            |            |                  |
| `top_p`          | \_float                                  | NotGiven\_                                                   | Top-p (nucleus) sampling parameter.  |            |                  |
| `extra_headers`  | \_Headers                                | None\_                                                       | Additional HTTP headers.             |            |                  |
| `extra_query`    | \_Query                                  | None\_                                                       | Additional query parameters.         |            |                  |
| `extra_body`     | \_Body                                   | None\_                                                       | Additional request body data.        |            |                  |
| `timeout`        | \_float                                  | httpx.Timeout                                                | None                                 | NotGiven\_ | Request timeout. |
| `**kwargs`       |                                          | Additional arguments, including 'stream' for streaming mode. |                                      |            |                  |

**Returns**:

| Name  | Description                                                                                                                  |
| ----- | ---------------------------------------------------------------------------------------------------------------------------- |
| `Any` | Either a direct message response or a [StreamWrapper](/sdk/python/references/logger/anthropic/stream_manager) for streaming. |

**Notes**:

The method automatically detects streaming mode via the 'stream' parameter
in kwargs and routes accordingly.

#### stream

```python theme={null}
def stream(*args, **kwargs) -> Any
```

Create a streaming message with [Maxim](/sdk/python/references/maxim) logging.

This method is a direct alias for create\_stream, providing compatibility
with the standard Anthropic Messages API while adding [Maxim](/sdk/python/references/maxim) logging.

**Arguments**:

| Name       | Description                                                                                      |
| ---------- | ------------------------------------------------------------------------------------------------ |
| `*args`    | [Variable](/sdk/python/references/models/dataset) length argument list passed to create\_stream. |
| `**kwargs` | Arbitrary keyword arguments passed to create\_stream.                                            |

**Returns**:

| Name                                                                      | Description                                         |
| ------------------------------------------------------------------------- | --------------------------------------------------- |
| `[StreamWrapper](/sdk/python/references/logger/anthropic/stream_manager)` | A wrapped stream manager with logging capabilities. |
