> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.OpenAIWrapper

<h2 id="autogen.OpenAIWrapper" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">OpenAIWrapper</span>
</h2>

```python theme={null}
OpenAIWrapper(
    *,
    config_list: Optional[list[dict[str, Any]]] = None,
    **base_config: Any
)
```

A wrapper class for openai client.<br />Initialize the OpenAIWrapper.<br />

<b>Parameters:</b>

| Name            | Description                                                              |
| --------------- | ------------------------------------------------------------------------ |
| `config_list`   | **Type:** Optional\[list\[dict\[str, Any]]]<br /><br />**Default:** None |
| `**base_config` | **Type:** Any                                                            |

### Class Attributes

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### actual\_usage\_summary

<br />

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### extra\_kwargs

<br />

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### total\_usage\_summary

<br />

<br />

### Static Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### extract\_text\_or\_completion\_object

```python theme={null}
extract_text_or_completion_object(response: ModelClientResponseProtocol) -> list[str] | list[Message]
```

Extract the text or ChatCompletion objects from a completion or chat response.<br />

<b>Parameters:</b>

| Name       | Description                                                                                                                                       |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `response` | The response from openai.<br /><br />**Type:** [ModelClientResponseProtocol](/docs/api-reference/autogen/ModelClient/ModelClientResponseProtocol) |

<b>Returns:</b>

| Type                                                                                           | Description                                                                                    |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| list\[str] \| list\[autogen.oai.client.ModelClient.ModelClientResponseProtocol.Choice.Message] | A list of text, or a list of ChatCompletion objects if function\_call/tool\_calls are present. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### instantiate

```python theme={null}
instantiate(
    template: Optional[Union[str, Callable[[dict[str, Any]], str]]],
    context: Optional[dict[str, Any]] = None,
    allow_format_str_template: Optional[bool] = False
) -> str | None
```

<b>Parameters:</b>

| Name                        | Description                                                          |
| --------------------------- | -------------------------------------------------------------------- |
| `template`                  | **Type:** Optional\[Union\[str, Callable\[\[dict\[str, Any]], str]]] |
| `context`                   | **Type:** Optional\[dict\[str, Any]]<br /><br />**Default:** None    |
| `allow_format_str_template` | **Type:** Optional\[bool]<br /><br />**Default:** False              |

<br />

### Instance Attributes

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### openai\_kwargs

<br />

<br />

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### clear\_usage\_summary

```python theme={null}
clear_usage_summary(self) -> None
```

Clear the usage summary.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### create

```python theme={null}
create(self, **config: Any) -> ModelClientResponseProtocol
```

Make a completion for a given config using available clients.<br />Besides the kwargs allowed in openai's \[or other] client, we allow the following additional kwargs.<br />The config in each client will be overridden by the config.<br />

<b>Parameters:</b>

| Name       | Description                                             |
| ---------- | ------------------------------------------------------- |
| `**config` | The config for the completion.<br /><br />**Type:** Any |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### print\_usage\_summary

```python theme={null}
print_usage_summary(self, mode: Union[str, list[str]] = ['actual', 'total']) -> None
```

Print the usage summary.

<b>Parameters:</b>

| Name   | Description                                                                    |
| ------ | ------------------------------------------------------------------------------ |
| `mode` | **Type:** Union\[str, list\[str]]<br /><br />**Default:** \['actual', 'total'] |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### register\_model\_client

```python theme={null}
register_model_client(
    self,
    model_client_cls: ModelClient,
    **kwargs: Any
) -> 
```

Register a model client.<br />

<b>Parameters:</b>

| Name               | Description                                                                                                                              |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `model_client_cls` | A custom client class that follows the ModelClient interface<br /><br />**Type:** [ModelClient](/docs/api-reference/autogen/ModelClient) |
| `**kwargs`         | **Type:** Any                                                                                                                            |

<br />
