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

# JavaScript

> Use the Mixfont JavaScript client

Use the JavaScript client in Node.js 18 or newer, or in server-side runtimes that provide `fetch`.

## Install

```bash theme={null}
npm install mixfont
```

View the package on [npm](https://www.npmjs.com/package/mixfont).

## Generate a font

```javascript theme={null}
import { Mixfont } from "mixfont";

const mixfont = new Mixfont({
  apiKey: process.env.MIXFONT_API_KEY,
});

const generation = await mixfont.generations.create({
  prompt: "a cute and bubbly font",
  glyphSet: "standard",
});

const result = await mixfont.generations.wait(generation.id);

console.log(result.ttfUrl);
```

## Create from an image

```javascript theme={null}
const generation = await mixfont.generations.create({
  imageUrl: "https://images.example.com/reference-wordmark.png",
  glyphSet: "standard",
});
```

## Methods

| Method                                  | Description                                                             |
| --------------------------------------- | ----------------------------------------------------------------------- |
| `mixfont.generations.create(options)`   | Starts a new generation and returns immediately.                        |
| `mixfont.generations.get(id)`           | Fetches the current generation status.                                  |
| `mixfont.generations.wait(id, options)` | Polls until the generation succeeds, fails, is cancelled, or times out. |

## Create options

Provide exactly one of `prompt` or `imageUrl`.

| Option     | Type                         | Description                                                                                                                                                                                                                 |
| ---------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `prompt`   | `string`                     | Text prompt for the generated font.                                                                                                                                                                                         |
| `imageUrl` | `string`                     | Public HTTPS URL for a reference image.                                                                                                                                                                                     |
| `glyphSet` | `"standard"` or `"extended"` | Optional glyph set. Defaults to `standard`. `standard` generates 72 glyphs for English with basic letters, numbers, and punctuation. `extended` generates 319 glyphs for all Latin languages, including special characters. |

## Response

The JavaScript client maps API response fields to camel case.

| Property          | Type               | Description                                                              |
| ----------------- | ------------------ | ------------------------------------------------------------------------ |
| `id`              | `string`           | Generation id.                                                           |
| `name`            | `string`           | Generated font display name.                                             |
| `ttfUrl`          | `string` or `null` | Generated TTF download URL. `null` until the generation succeeds.        |
| `status`          | `string`           | `preparing`, `queued`, `running`, `succeeded`, `cancelled`, or `failed`. |
| `inputType`       | `string`           | `text` or `image`.                                                       |
| `glyphSet`        | `string`           | Selected glyph set: `standard` or `extended`.                            |
| `progressPercent` | `number`           | Approximate progress from `0` to `100`.                                  |
| `pollUrl`         | `string`           | Present on create responses.                                             |
| `error`           | `string`           | Present only when a generation fails and an error message is available.  |
| `createdAt`       | `string`           | ISO timestamp for when the generation was created.                       |

## Wait options

| Option       | Type          | Description                              |
| ------------ | ------------- | ---------------------------------------- |
| `intervalMs` | `number`      | Polling interval. Defaults to `5000`.    |
| `timeoutMs`  | `number`      | Maximum wait time. Defaults to `600000`. |
| `signal`     | `AbortSignal` | Optional abort signal.                   |
