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

# Zero-Inference Design

> How SuperModel eliminates server-side LLM costs completely

# Zero-Inference Design

SuperModel's core innovation is achieving complete zero-inference operation on the server side by using [MCP sampling](https://modelcontextprotocol.org) for ALL decision-making points, from request routing to UI generation.

## The Traditional Problem

Most generative UI systems require expensive server-side LLM inference:

```mermaid
graph LR
    User[User Request] --> Server[Server]
    Server --> LLM1[$$$ Routing LLM]
    LLM1 --> Server
    Server --> Tool[UI Tool]
    Tool --> LLM2[$$$ Generation LLM]
    LLM2 --> Tool
    Tool --> Server
    Server --> UI[Generated UI]
    
    style LLM1 fill:#ef4444,color:#fff
    style LLM2 fill:#ef4444,color:#fff
```

**Problems**:

* High inference costs for every request
* Need to maintain LLM infrastructure
* Scaling costs increase linearly with usage
* Complex model management and versioning

## SuperModel's Solution

SuperModel flips the model by using the client's LLM for all reasoning through MCP sampling:

```mermaid
graph LR
    User[User Request] --> Server[Server]
    Server --> Sampling1[MCP Sampling]
    Sampling1 --> ClientLLM[Client LLM]
    ClientLLM --> Sampling1
    Sampling1 --> Server
    Server --> Tool[UI Tool]
    Tool --> Sampling2[MCP Sampling]
    Sampling2 --> ClientLLM
    ClientLLM --> Sampling2
    Sampling2 --> Tool
    Tool --> Server
    Server --> UI[Generated UI]
    
    style ClientLLM fill:#22c55e,color:#fff
    style Server fill:#6366f1,color:#fff
```

**Benefits**:

* **\$0 server inference costs**
* **No LLM infrastructure needed**
* **Infinite scaling** (costs stay at \$0)
* **Client controls LLM choice** and quality

## How Zero-Inference Works

### 1. Request Routing via Sampling

Instead of using a server-side LLM to determine routing, SuperModel asks the client:

<Tabs>
  <Tab title="Traditional Approach">
    ```typescript
    // Server pays for LLM inference
    const routingDecision = await serverLLM.analyze({
      prompt: "Which tool should handle this request?",
      context: userRequest
    });

    // Cost: $0.01-0.10 per request
    ```
  </Tab>

  <Tab title="SuperModel Approach">
    ```typescript
    // Client's LLM handles the decision
    const routingDecision = await gateway.sample({
      messages: [{
        role: "user",
        content: {
          type: "text", 
          text: `User request: "${userRequest}"\n\nAvailable tools: ${toolList}\n\nWhich tool should handle this?`
        }
      }],
      systemPrompt: "You are a routing assistant. Return JSON with tool selection."
    });

    // Cost: $0.00 (client pays)
    ```
  </Tab>
</Tabs>

### 2. UI Generation via Sampling

Similarly, UI generation delegates all creative work to the client:

```json
{
  "method": "sampling/createMessage",
  "params": {
    "messages": [{
      "role": "user", 
      "content": {
        "type": "text",
        "text": "Generate a React component for product search with these requirements:\n- Grid layout with images\n- Price and category filters\n- Sort dropdown\n- Add to cart buttons\n\nUse AG-UI event system for interactions.\n\nProduct data: [...products]"
      }
    }],
    "systemPrompt": "You are an expert React developer. Generate clean, functional AG-UI components.",
    "maxTokens": 2000
  }
}
```

**The server never interprets or modifies the generated code** - it simply packages whatever the client's LLM returns.

### 3. Context Management via Sampling

Even complex multi-step workflows use sampling for decision-making:

<CodeGroup>
  ```json Context-Aware Routing
  {
    "method": "sampling/createMessage",
    "params": {
      "messages": [{
        "role": "user",
        "content": {
          "type": "text", 
          "text": "User wants to complete their shopping journey. Previous context:\n\n{\"selected_products\": [\"headphones-1\"], \"budget\": \"$200\", \"use_case\": \"work_from_home\"}\n\nUser just said: 'Add a carrying case and checkout'\n\nAvailable tools:\n- bundle-builder-ui: Add complementary products\n- checkout-ui: Complete purchase\n- product-search-ui: Find more products\n\nWhich tool should handle this next step?"
        }
      }],
      "systemPrompt": "Consider the user journey and context. Return the best next tool."
    }
  }
  ```

  ```json Client Response
  {
    "role": "assistant",
    "content": {
      "type": "text",
      "text": "{\"tool\": \"bundle-builder-ui\", \"context\": {\"add_accessory\": \"carrying_case\", \"next_action\": \"checkout\", \"existing_selection\": [\"headphones-1\"]}}"
    }
  }
  ```
</CodeGroup>

## Cost Comparison

<div className="overflow-x-auto">
  <table className="min-w-full">
    <thead>
      <tr className="border-b">
        <th className="text-left p-2">Scenario</th>
        <th className="text-left p-2">Traditional</th>
        <th className="text-left p-2">SuperModel</th>
        <th className="text-left p-2">Savings</th>
      </tr>
    </thead>

    <tbody>
      <tr className="border-b">
        <td className="p-2">Simple Calculator</td>
        <td className="p-2">$0.05</td>         <td className="p-2">$0.00</td>
        <td className="p-2">100%</td>
      </tr>

      <tr className="border-b">
        <td className="p-2">E-commerce Search</td>
        <td className="p-2">$0.15</td>         <td className="p-2">$0.00</td>
        <td className="p-2">100%</td>
      </tr>

      <tr className="border-b">
        <td className="p-2">Multi-App Workflow</td>
        <td className="p-2">$0.50</td>         <td className="p-2">$0.00</td>
        <td className="p-2">100%</td>
      </tr>

      <tr className="border-b">
        <td className="p-2">1000 Requests/Day</td>
        <td className="p-2">$150/day</td>         <td className="p-2">$0/day</td>
        <td className="p-2">\$54,750/year</td>
      </tr>
    </tbody>
  </table>
</div>

## Implementation Guarantees

SuperModel enforces zero-inference through architectural constraints:

<AccordionGroup>
  <Accordion title="Compilation-Time Checks">
    The SuperModel framework includes TypeScript interfaces that make it impossible to call LLM APIs directly:

    ```typescript
    interface SuperModelTool {
      // No direct LLM access allowed
      process(request: Request, context: Context): Promise<UIResource>;
      
      // Only sampling is available
      sample(prompt: SamplingRequest): Promise<SamplingResponse>;
    }
    ```
  </Accordion>

  <Accordion title="Runtime Monitoring">
    SuperModel can optionally monitor for unexpected LLM API calls:

    ```typescript
    // Optional: Block all outbound LLM API calls
    gateway.enableInferenceMonitoring({
      blockOpenAI: true,
      blockAnthropic: true, 
      blockOllama: true,
      onViolation: (call) => {
        throw new Error(`Unexpected LLM call detected: ${call.url}`);
      }
    });
    ```
  </Accordion>

  <Accordion title="Deployment Validation">
    SuperModel servers can run in environments with no LLM API access to prove zero-inference:

    ```bash
    # Deploy with no internet access to LLM APIs
    docker run --network=isolated supermodel-server

    # Still functions perfectly with MCP sampling
    ```
  </Accordion>
</AccordionGroup>

## Performance Implications

### Latency Considerations

<Warning>
  **Slight Latency Increase**: Zero-inference comes with 500-2000ms additional latency for MCP sampling round-trips.
</Warning>

<div className="grid grid-cols-2 gap-4">
  <div>
    **Traditional**

    * Server LLM: 500-1500ms
    * **Total**: 500-1500ms
  </div>

  <div>
    **SuperModel**

    * MCP Sampling: 1000-3000ms
    * **Total**: 1000-3000ms
  </div>
</div>

### Optimization Strategies

<Steps>
  <Step title="Parallel Sampling">
    Execute routing and context analysis in parallel when possible
  </Step>

  <Step title="Caching">
    Cache common routing decisions and UI patterns
  </Step>

  <Step title="Streaming">
    Stream UI generation for immediate user feedback
  </Step>

  <Step title="Preloading">
    Preload likely next tools based on user journey patterns
  </Step>
</Steps>

## When Zero-Inference Makes Sense

<CardGroup cols={2}>
  <Card title="High Volume Applications" icon="chart-line">
    Applications with thousands of daily requests where inference costs would be significant.
  </Card>

  <Card title="Cost-Sensitive Deployments" icon="dollar-sign">
    Startups, open-source projects, or applications with tight budgets.
  </Card>

  <Card title="Client-Controlled Quality" icon="shield-check">
    When you want users to control their LLM choice and quality settings.
  </Card>

  <Card title="Regulatory Compliance" icon="lock">
    When data cannot leave the client environment for LLM processing.
  </Card>
</CardGroup>

## Trade-offs to Consider

<AccordionGroup>
  <Accordion title="Latency vs Cost">
    SuperModel trades some latency (500-2000ms) for complete cost elimination. Consider if this trade-off makes sense for your use case.
  </Accordion>

  <Accordion title="Client Capability Dependence">
    UI quality depends on the client's LLM capability. A client with a weak LLM will generate lower-quality UIs.
  </Accordion>

  <Accordion title="Network Dependency">
    Requires reliable client-server communication for sampling. Network issues affect functionality.
  </Accordion>

  <Accordion title="MCP Client Requirement">
    Only works with MCP clients that support sampling. Traditional REST API clients cannot use SuperModel.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Gateway Pattern" icon="route" href="/concepts/gateway-pattern">
    Learn how SuperModel implements intelligent routing without inference.
  </Card>

  <Card title="Hello World Example" icon="play" href="/examples/hello-world">
    See zero-inference in action with a step-by-step example.
  </Card>
</CardGroup>
