## Use Clarifai’s Reasoning Engine for optimized predictions

---

[Clarifai's Reasoning Engine](/content/press-release-clarifai-launches-reasoning-engine-optimized-for-agentic-ai-inference/index.html) delivers a fast, scalable, and streamlined way to run model inferences at production quality.

Designed with a Python-first, developer-friendly architecture, it provides a powerful and flexible approach that minimizes operational overhead — allowing you to run predictions quickly, accurately, and cost-effectively.

**Tip**  
Check out [this repository](https://github.com/toswari-ai/demo-clarifai-api) for beginner-friendly examples on using Clarifai AI models for text, image, audio, and multimodal inference tasks.

## Prerequisites

### Install Clarifai Packages

- Install the latest version of the Clarifai [Python](https://github.com/Clarifai/clarifai-python/) SDK package:

```bash
pip install --upgrade clarifai
```

- Install the latest version of the Clarifai [Node.js](https://github.com/Clarifai/clarifai-nodejs) SDK package:

```bash
npm install clarifai-nodejs
```

### Get a PAT Key  
You need a PAT (Personal Access Token) key to authenticate your connection to the Clarifai platform. Learn how to get it [here](https://docs.clarifai.com/control/authentication/pat/#how-to-create-a-pat-on-the-platform).

## Structure of Prediction Methods

Before making a prediction with a model, it’s important to understand how its prediction methods are structured.

You can learn more about the structure of model prediction methods [here](https://docs.clarifai.com/compute/inference/#structure-of-prediction-methods).

### Get Available Methods

You can list all the methods implemented in the model's configuration that are available for performing model inference.

```python
from clarifai.client import Model

# Set PAT as an environment variable
#   export CLARIFAI_PAT=YOUR_PAT_HERE # Unix-Like Systems
#   set CLARIFAI_PAT=YOUR_PAT_HERE  # Windows

# Initialize with model URL
model = Model(url="https://clarifai.com/openai/chat-completion/models/o4-mini")

model_methods = model.available_methods()

print(model_methods)
```

```javascript
import { Model } from "clarifai-nodejs";

const model = new Model({
  url: "https://clarifai.com/openai/chat-completion/models/o4-mini",
  authConfig: {
    pat: process.env.CLARIFAI_PAT,
  },
});

const modelMethods = await model.availableMethods();

console.log(modelMethods);
```

**Example Output**  
```text
dict_keys(['predict', 'generate', 'chat'])
```

### Get Method Signature

You can retrieve the method signature of a specified model's method to identify all its arguments and their type annotations, which are essential for performing model inference.

A method signature defines the method's name, its input parameters (with types and default values), and the return type, helping you understand how to properly call the method.

```python
from clarifai.client import Model

# Set PAT as an environment variable
#   export CLARIFAI_PAT=YOUR_PAT_HERE # Unix-Like Systems
#   set CLARIFAI_PAT=YOUR_PAT_HERE  # Windows

# Initialize with model URL
model = Model(url="https://clarifai.com/openai/chat-completion/models/o4-mini")

method_name = "predict" # Or, "generate", "chat", etc

method_signature = model.method_signature(method_name= method_name)

print(method_signature)
```

```javascript
import { Model } from "clarifai-nodejs";

const model = new Model({
  url: "https://clarifai.com/openai/chat-completion/models/o4-mini",
  authConfig: {
    pat: process.env.CLARIFAI_PAT,
  },
});

const methodSignatures = await model.methodSignatures();

console.log(methodSignatures);
```

**Example Output**  
```text
def predict(prompt: str, image: data_types.Image, images: Any, chat_history: Any, max_tokens: float = 512.0, temperature: float = 1.0, top_p: float = 0.8, reasoning_effort: str = '"low"') -> str:
```

### Generate Example Code

You can generate a sample code snippet to better understand how to perform inference using a model.

```python
from clarifai.client import Model

# Set PAT as an environment variable
#   export CLARIFAI_PAT=YOUR_PAT_HERE # Unix-Like Systems
#   set CLARIFAI_PAT=YOUR_PAT_HERE  # Windows

# Initialize with model URL
model = Model(url="https://clarifai.com/openai/chat-completion/models/o4-mini")

model_script = model.generate_client_script()

print(model_script)
```

**Example Output**  
```text
# Clarifai Model Client Script
# Set the environment variables `CLARIFAI_DEPLOYMENT_ID` and `CLARIFAI_PAT` to run this script.
# Example usage:
from clarifai.runners.utils import data_types
import os
from clarifai.client import Model

model = Model("www.clarifai.com/openai/chat-completion/o4-mini",
    deployment_id = os.environ['CLARIFAI_DEPLOYMENT_ID'], # Only needed for dedicated deployed models
)

# Example model prediction from different model methods:

response = model.predict(prompt='What is the future of AI?', image=Image(url='https://samples.clarifai.com/metro-north.jpg'), images=None, chat_history=None, max_tokens=512.0, temperature=1.0, top_p=0.8, reasoning_effort='"low"')
print(response)

response = model.generate(prompt='What is the future of AI?', image=Image(url='https://samples.clarifai.com/metro-north.jpg'), images=None, chat_history=None, max_tokens=512.0, temperature=0.7, top_p=0.8, reasoning_effort='"low"')
for res in response:
    print(res)

response = model.chat(messages=None, max_tokens=750.0, temperature=0.7, top_p=0.8, reasoning_effort='"low"')
for res in response:
    print(res)
```
