directus-extension-genmagic
v1.0.0
Published
Generate images, video and speech from a Flow with Veo, Kling, Flux and the other models on GenMagic.
Maintainers
Readme
GenMagic for Directus
Generate images, video and speech from inside a Directus Flow. Add the GenMagic step, pick what to make, and the next step gets a link to the finished file and what it cost. Models include Veo, Kling, Flux and the other image, video and voice models on GenMagic.
It runs in the Directus sandbox, so it works on Directus Cloud and on self-hosted projects that keep the default Marketplace settings. Tested on Directus 11.17 and 12.6.
Set up
- In Directus, open Settings, Marketplace, search for GenMagic and install it. On a self-hosted project you can also run
npm install directus-extension-genmagicin your extensions folder. - Get a GenMagic API key. A free key is at genmagic.co/get-api-key. Each generation is billed from your GenMagic balance at the price shown for that model on genmagic.co/models.
- In Settings, Flows, create or open a Flow, add a step, and choose GenMagic.
- Paste the key into GenMagic API key (the field is masked), choose an Action, and fill in the prompt or text.
To keep the key out of the Flow, store it as an environment variable, list its name in FLOWS_ENV_ALLOW_LIST (for example GENMAGIC_API_KEY) and put {{ $env.GENMAGIC_API_KEY }} in the key field.
The step
One step does all three jobs. The Action dropdown decides which fields show.
| Action | Field | What to enter |
|---|---|---|
| All | GenMagic API key | Your key. Masked. |
| All | Model | A model id from genmagic.co/models, such as provider/model-name. Leave it empty to use GenMagic's default for that action. |
| Generate Image | Prompt | What to draw. {{ }} references to earlier steps work. |
| Generate Image | Size | 1024x1024, 1792x1024 or 1024x1792. Optional. |
| Generate Image, Generate Video | Reference image URL | Optional. An https URL (or data:image URL) to edit, or to open the video on. |
| Generate Video | Prompt | What happens in the clip. |
| Generate Video | Aspect ratio | 16:9, 9:16 or 1:1. Optional. |
| Generate Video | Duration (seconds) | Optional. Must be a length the chosen model offers. The price grows with it. |
| Generate Video | Max wait (seconds) | How long the step waits for the clip. Default 600, from 10 to 3600. |
| Text to Speech | Text to speak | The words to read aloud. |
| Text to Speech | Voice | Optional voice name, for example alloy. |
If you type a model id that does not exist, or one that makes the wrong kind of file for the chosen action, the step says so before anything is billed.
What the step returns
The next steps can read these as {{ your_step_key.url }} and so on.
| Key | Meaning |
|---|---|
| action | image, video or speech |
| url | Link to the finished file, hosted by GenMagic |
| cost_cents | What this call cost, in US cents (can be fractional). null if GenMagic did not report it. |
| credits_remaining_cents | Your balance after the call, in US cents. null if not reported. |
| id | Video only: the GenMagic job id |
Example: a cover image for every new article
- Trigger: Event Hook, type Action (Non-Blocking), event
items.create, collectionarticles. - GenMagic with key
cover: Action Generate Image, PromptEditorial illustration for an article titled: {{ $trigger.payload.title }}. - Webhook / Request URL with key
import: methodPOST, URLhttps://your-project.example.com/files/import, a headerAuthorization: Bearer <a static token of a user who can create files>, and body{ "url": "{{ cover.url }}" }. - An Update Data step that stores
{{ import.data.data.id }}in the article's image field.
Video takes minutes
Generate Video starts the job, then checks on it every few seconds until the clip is ready or Max wait runs out. A clip usually takes a few minutes, so do not put it in a Flow that makes a person or a web request wait. Use an Event Hook set to Action (Non-Blocking), a Schedule, or a Webhook with Asynchronous switched on.
If Max wait runs out, the step fails and its message names the job id. GenMagic keeps rendering that job and bills it only if it completes. Raise Max wait to wait longer.
When something goes wrong
The step takes the Flow's reject path and $last.message says what happened. Directus's sandbox only tells an extension the HTTP status of a refused call, not the reply text, so the message states what that status means for GenMagic: a missing or wrong key (401), a balance too low for the call (402), a rate limit of 300 requests a minute (429), or a request GenMagic refused (400). A video that fails while rendering reports GenMagic's own reason.
Permissions
The extension runs in the Directus sandbox and asks for three things only: write a line to the server log, wait between video checks, and send GET and POST requests to https://genmagic.co/api/v1/. It cannot reach your database, your files or any other website. What it sends to GenMagic is your key, the prompt or text, the model, the options above, and the reference image URL if you set one.
Links
MIT licensed.
