# ModelClient

## ``autogen.ModelClient``

Bases: `Protocol`

A client class must implement the following methods: 
- `create` must return a response object that implements the `ModelClientResponseProtocol`
- `cost` must return the cost of the response
- `get_usage` must return a dict with the following keys:
  - `prompt_tokens`
  - `completion_tokens`
  - `total_tokens`
  - `cost`
  - `model`

This class is used to create a client that can be used by OpenAIWrapper. The response returned from `create` must adhere to the `ModelClientResponseProtocol` but can be extended however needed. The `message_retrieval` method must be implemented to return a list of str or a list of messages from the response.

### ``RESPONSE_USAGE_KEYS``

```python
RESPONSE_USAGE_KEYS = ['prompt_tokens', 'completion_tokens', 'total_tokens', 'cost', 'model']
```

### ``ModelClientResponseProtocol``

Bases: `Protocol`

#### ``choices``

``choices``

#### ``model``

``model``

#### ``Choice``

Bases: `Protocol`

##### ``message``

``message``

##### ``Message``

Bases: `Protocol`

###### ``content``

``content``

### ``create``

``create(params)``

Source code in `autogen/llm_config/client.py`

|     |     |
| --- | --- |
| ```<br>42<br>``` | ```<br>def create(self, params: dict[str, Any]) -> ModelClientResponseProtocol: ...  # pragma: no cover<br>``` |

### ``message_retrieval``

``message_retrieval(response)``

Retrieve and return a list of strings or a list of `Choice.Message` from the response.

NOTE: if a list of `Choice.Message` is returned, it currently needs to contain the fields of OpenAI's ChatCompletion Message object, since that is expected for function or tool calling in the rest of the codebase at the moment, unless a custom agent is being used.

Source code in `autogen/llm_config/client.py`

|     |     |
| --- | --- |
| ```<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>51<br>52<br>``` | ```<br>def message_retrieval(<br>    self, response: ModelClientResponseProtocol<br>) -> list[str] | list["ModelClient.ModelClientResponseProtocol.Choice.Message"]:<br>    """Retrieve and return a list of strings or a list of Choice.Message from the response.<br>    NOTE: if a list of Choice.Message is returned, it currently needs to contain the fields of OpenAI's ChatCompletion Message object,<br>    since that is expected for function or tool calling in the rest of the codebase at the moment, unless a custom agent is being used.<br>    """<br>    ...  # pragma: no cover<br>``` |

### ``cost``

``cost(response)``

Source code in `autogen/llm_config/client.py`

|     |     |
| --- | --- |
| ```<br>54<br>``` | ```<br>def cost(self, response: ModelClientResponseProtocol) -> float: ...  # pragma: no cover<br>``` |

### ``get_usage``

``get_usage(response)``

Return usage summary of the response using `RESPONSE_USAGE_KEYS`.

Source code in `autogen/llm_config/client.py`

|     |     |
| --- | --- |
| ```<br>56<br>57<br>58<br>59<br>``` | ```<br>@staticmethod<br>def get_usage(response: ModelClientResponseProtocol) -> dict[str, Any]:<br>    """Return usage summary of the response using RESPONSE_USAGE_KEYS."""<br>    ...  # pragma: no cover<br>``` |
