Skip to main content
The ModelState type defines the configuration state for real-time models, including prompt and image inputs.

Type Definition

type ModelState = {
  prompt?: {
    text: string;
    enhance?: boolean;
  };
  image?: Blob | File | string;
};

Fields

prompt

prompt
object
The text prompt configuration for the model.

image

image
Blob | File | string
Reference image input for models that support image conditioning. Can be:
  • Blob - Binary image data
  • File - File object from file input
  • string - Base64-encoded image data or URL

Usage Examples

With Prompt Only

import { createDecartClient, models } from '@decartai/sdk';

const client = createDecartClient({ apiKey: 'your-api-key' });

const state: ModelState = {
  prompt: {
    text: 'A serene mountain landscape',
    enhance: true
  }
};

await client.realtime.connect({
  model: models.realtime('mirage'),
  state
});

With Image Reference

const imageFile = document.getElementById('upload').files[0];

const state: ModelState = {
  prompt: {
    text: 'Transform this into a watercolor painting',
    enhance: false
  },
  image: imageFile
};

await client.realtime.connect({
  model: models.realtime('lucy_2_rt'),
  state
});

With Base64 Image

const state: ModelState = {
  image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...'
};

await client.realtime.connect({
  model: models.realtime('lucy_2_rt'),
  state
});
  • connect() - Initialize real-time connection with ModelState
  • setImage() - Update image during active session
  • sendPrompt() - Send new prompt during active session

Validation

The SDK validates ModelState using a Zod schema at runtime:
import { modelStateSchema } from '@decartai/sdk';

// Validate state before use
const result = modelStateSchema.safeParse(state);
if (!result.success) {
  console.error(result.error);
}

Notes

  • The prompt.text field must be at least 1 character when provided
  • Prompt enhancement is enabled by default to improve generation quality
  • Not all real-time models support image inputs - check model capabilities
  • Image data is automatically converted to the appropriate format for the API

Build docs developers (and LLMs) love