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

# Wrap Model Call • AI Agent SDK

> wrap_model_call: Decorator to mark a function as a wrap_model_call middleware.

# wrap\_model\_call

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**middleware**](../modules/middleware) module.

Decorator to mark a function as a wrap\_model\_call middleware.

The function receives (request, call\_next) and should call call\_next(request)
to continue the chain, or return early to short-circuit.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def wrap_model_call(func: WrapModelCallFn) -> WrapModelCallFn
```

## Parameters

<ParamField query="func" type="WrapModelCallFn" required={true}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="WrapModelCallFn">
  The result of the operation.
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@wrap_model_call
    def retry_on_error(request, call_next):
        for _ in range(3):
            try:
                return call_next(request)
            except Exception:
                pass
        raise RuntimeError("All retries failed")
```

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/hooks/middleware.py#L221">
  `praisonaiagents/hooks/middleware.py` at line 221
</Card>
