---
sidebar_position: 1
title: "🚰 Pipe Function"
---


import Common from './tab-shared/Common.md';


#### Pipe
A Pipe is used to create a "Model" with custom logic and processing. A Pipe will always show up as its own singular model in the OpenWebUI interface.

A Pipe has a single main component called a **pipe function**. This component encapsulates all of the primary logic that the Pipe will perform.

<details>
<summary>Example</summary>

```
class Pipe:
    class Valves(BaseModel):
        RANDOM_CONFIG_OPTION: str = Field(default="")

    def __init__(self):
        self.type = "pipe"
        self.id = "blah"
        self.name = "Testing"
        self.valves = self.Valves(
            **{"RANDOM_CONFIG_OPTION": os.getenv("RANDOM_CONFIG_OPTION", "")}
        )
        pass

    def get_provider_models(self):
        return [
            {"id": "model_id_1", "name": "model_1"},
            {"id": "model_id_2", "name": "model_2"},
            {"id": "model_id_3", "name": "model_3"},
        ]

    def pipe(self, body: dict) -> Union[str, Generator, Iterator]:
      # Logic goes here
      return body
```
</details>

#### Manifold
A Manifold is used to create a collection of Pipes. If a Pipe creates a singular "Model", a Manifold creates a set of "Models." Manifolds are typically used to create integrations with other model providers, such as Anthropic or Groq.

A Manifold has two main components:

##### Pipes Function
This is used to simply initiate a dictionary to hold all of the Pipes created by the manifold.

##### Pipe Function
As referenced above, this component encapsulates all of the primary logic that the Pipe will perform.


<details>
<summary>Example</summary>

```
class Pipe:
    class Valves(BaseModel):
        PROVIDER_API_KEY: str = Field(default="")

    def __init__(self):
        self.type = "manifold"
        self.id = "blah"
        self.name = "Testing"
        self.valves = self.Valves(
            **{"PROVIDER_API_KEY": os.getenv("PROVIDER_API_KEY", "")}
        )
        pass

    def get_provider_models(self):
        return [
            {"id": "model_id_1", "name": "model_1"},
            {"id": "model_id_2", "name": "model_2"},
            {"id": "model_id_3", "name": "model_3"},
        ]

    def pipes(self) -> List[dict]:
        return self.get_provider_models()

    def pipe(self, body: dict) -> Union[str, Generator, Iterator]:
      # Logic goes here
      return body
```
</details>

Note: To differentiate between a Pipe and a Manifold you will need to specify the type in def init:
```
def __init__(self):
        self.type = "pipe"
        self.id = "blah"
        self.name = "Testing"
        pass
```

or

```
def __init__(self):
        self.type = "manifold"
        self.id = "blah"
        self.name = "Testing/"
        pass
```

<Common/>