Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.4.0+

Simple AI Image Generation

See more AI Examples

Create an image by providing a text description.

Chilkat React Native Downloads

React Native
import { Ai, BinData, JsonObject } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const ai = new Ai();

  ai.provider = 'openai';

  // Use your provider's API key.
  ai.apiKey = 'MY_API_KEY';

  // Choose a model.
  ai.model = 'gpt-5.6-terra';

  const askParams = new JsonObject();
  askParams.updateString('image.output_format', 'jpeg');
  askParams.updateString('image.size', '1024x1024');
  askParams.updateString('image.quality', 'low');
  ai.setAskParams(askParams);

  ai.inputAddText('Generate a small, cute illustration of a gray tabby cat hugging a happy otter wearing an orange scarf');

  // Ask the AI for image output.
  try {
    await ai.askAsync('image');
  } catch {
    console.log(ai.lastErrorText);
    return;
  }

  // Get the image response data.
  const bdImageData = new BinData();
  try {
    ai.getOutputBd(bdImageData);
  } catch {
    console.log(ai.lastErrorText);
    return;
  }

  bdImageData.writeFile('c:/aaworkarea/out.jpg');

  console.log('Success.');
}