# How to Configure a Custom API Endpoint for a New Model in MuapiClient

> Learn to configure a custom API endpoint for your new models in MuapiClient. Easily add custom endpoints to the model catalog and route requests efficiently. Get started now!

- Repository: [Anil Chandra Naidu Matcha/Open-Generative-AI](https://github.com/Anil-matcha/Open-Generative-AI)
- Tags: how-to-guide
- Published: 2026-04-24

---

**Add a new entry with a custom `endpoint` field to the model catalog in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js), then reference the model's `id` when calling `muapi.generateImage()` to automatically route requests to your specified API path.**

The Open-Generative-AI repository uses a dynamic model catalog to resolve API endpoints at runtime. When you invoke a generation method, the Muapi client checks the model registry in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) to determine the destination URL. This architecture lets you register new models and their custom endpoints without modifying the core client logic.

## Understanding the Endpoint Resolution Logic

The Muapi client builds request URLs dynamically based on the model definition you provide. According to the source code in [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js) (lines 30‑33), the endpoint resolution follows this precedence:

```javascript
const endpoint = modelInfo?.endpoint || params.model;

```

Here is the lookup process:

1. **Model Lookup**: The client searches the exported `t2iModels` array in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) for an entry matching the `model` parameter you passed.
2. **Endpoint Extraction**: If found, it reads the **`endpoint`** field from that model's configuration object.
3. **Fallback Behavior**: If no matching model definition exists, the client uses the raw `model` string you provided as the endpoint path.

The final request URL concatenates the Muapi base URL (`https://api.muapi.ai/api/v1/`) with this resolved endpoint value.

## Step-by-Step Configuration Guide

Follow these steps to register a new model with a custom API endpoint in the MuapiClient.

### Define the Model in models.js

Open [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) and locate the exported array beginning with `export const t2iModels = [`. Append a new object containing at least these required fields:

- **`id`**: A unique string identifier used to reference the model in code.
- **`name`**: A human-readable label displayed in the Studio UI.
- **`endpoint`**: The custom API path segment appended to the base URL.
- **`inputs`**: A schema object describing the parameters your endpoint accepts.

### Sync the Studio UI (Optional)

The Studio interface reads from [`packages/studio/src/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/packages/studio/src/models.js), which is auto-generated from the source file. After editing [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js), rebuild the project or run the generation script (commonly `npm run generate-models`) to populate the dropdown menus with your new model.

### Invoke the Model in Your Code

When calling generation methods like `muapi.generateImage()`, pass the **`id`** of your new model as the `model` parameter. The client will automatically resolve this to your custom endpoint.

## Code Examples

### Adding a Custom Model Definition

Add this object to the `t2iModels` array in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js):

```javascript
// src/lib/models.js
{
  id: "my-custom-diffusion",
  name: "My Custom Diffusion Model",
  endpoint: "custom-diffusion-v2/generate",
  inputs: {
    prompt: {
      title: "Prompt",
      name: "prompt",
      type: "string",
      description: "Text prompt for image generation",
      examples: ["A cyberpunk cityscape"]
    },
    guidance_scale: {
      title: "Guidance Scale",
      name: "guidance_scale",
      type: "number",
      default: 7.5
    }
  }
}

```

The `endpoint` value `"custom-diffusion-v2/generate"` will be combined with the base URL to create `https://api.muapi.ai/api/v1/custom-diffusion-v2/generate`.

### Calling the Custom Endpoint

Reference the model by its `id` in your application code:

```javascript
import { muapi } from '../lib/muapi.js';

async function generateImage() {
  const result = await muapi.generateImage({
    model: 'my-custom-diffusion',  // Matches the id in models.js
    prompt: 'A futuristic skyline at sunset',
    guidance_scale: 8.0
  });
  
  return result.url;
}

```

Alternatively, you can bypass the model catalog entirely by passing the endpoint string directly:

```javascript
// Uses the string as the endpoint since no modelInfo exists
const result = await muapi.generateImage({
  model: 'custom-diffusion-v2/generate',
  prompt: 'Abstract art'
});

```

## Key Implementation Details

| File | Purpose | Critical Lines |
|------|---------|----------------|
| [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js) | Core client handling HTTP requests | Lines 30‑33: `const endpoint = modelInfo?.endpoint \|\| params.model;` |
| [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) | Master registry of all supported models | Contains `export const t2iModels = [...]` with objects defining `id`, `name`, `endpoint` |
| [`packages/studio/src/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/packages/studio/src/models.js) | Studio UI model list | Auto-generated mirror of [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) |

Ensure your `endpoint` value exactly matches the path exposed by the Muapi service, as the resolution is case-sensitive. The client performs no deep validation of input parameters against your schema, so mismatched fields will result in a `400` error from the server rather than a client-side warning.

## Summary

- **Register models** by adding objects to the `t2iModels` array in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js).
- **Define custom endpoints** using the `endpoint` field in your model configuration.
- **Reference by ID** when calling methods like `muapi.generateImage({ model: 'your-id' })`.
- **Bypass the catalog** by passing the endpoint string directly if you prefer not to register a formal definition.
- **Rebuild the UI** to see new models in the Studio dropdown by regenerating [`packages/studio/src/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/packages/studio/src/models.js).

## Frequently Asked Questions

### What file contains the model definitions in the Open-Generative-AI repository?

The master list lives in **[`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js)**, which exports an array named `t2iModels`. Each object in this array defines the `id`, `name`, `endpoint`, and input schema for a specific model supported by the MuapiClient.

### Can I use a custom endpoint without adding it to models.js?

Yes. If you pass an endpoint string that doesn't match any `id` in the catalog, the client uses that string directly as the endpoint path due to the fallback logic `modelInfo?.endpoint || params.model` in [`src/lib/muapi.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/muapi.js). However, registering the model provides benefits like input validation schemas and Studio UI integration.

### How does the MuapiClient construct the final URL for API requests?

The client concatenates the base URL (`https://api.muapi.ai/api/v1/`) with the resolved endpoint value. The endpoint comes either from the `endpoint` field of a matched model definition in [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) or falls back to the raw `model` parameter you provided.

### Why isn't my new model appearing in the Studio UI dropdown?

The Studio application reads from **[`packages/studio/src/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/packages/studio/src/models.js)**, which is generated from the master [`src/lib/models.js`](https://github.com/Anil-matcha/Open-Generative-AI/blob/main/src/lib/models.js) file. You must rebuild the project or run the model generation script (typically `npm run generate-models`) to sync the changes, then restart the development server for the UI to reflect the updated catalog.