Loading components
Run GMI Cloud chat, image, and video jobs from Convex with built-in usage tracking, model caching, and durable polling with reactive job status.
npm install @alhwyn/convex-gmi-cloudGMI Cloud for Convex brings AI inference into your Convex backend with a small TypeScript API. Send chat requests, cache the model catalog, and keep usage records alongside your application data.
Track prompt and completion tokens, request latency, and usage totals by model or user. For image and video workflows, submit a job once and let Convex schedule status checks, store results, enforce a timeout, and call your completion handler. Reactive queries let your interface follow each job without building a separate polling service.
Use it for chat assistants, AI features, and media generation workflows. Install @alhwyn/convex-gmi-cloud, register the component, and configure GMI_CLOUD_API_KEY on the server. Your application controls authentication and access to user data; GMI handles model inference and media processing.
Created and maintained by Alhwyn Geonzon, a GMI Cloud Ambassador.
The GMI Cloud component for Convex lets you submit image generation jobs via gmi.submitJob() from an authenticated action. The component schedules its own status checks, backs off polling from 1 second up to 30 seconds, enforces a configurable timeout, and stores the result including media URLs. You query job state reactively using gmi.getJob() or gmi.listJobs() without writing any polling logic.
After calling gmi.chat() with a userId derived from the authenticated identity, the GMI Cloud component records prompt tokens, completion tokens, request latency, and status in your Convex database. Call gmi.usage() for recent records or gmi.usageTotals() for per-model aggregates without scanning history. Prompts and credentials are not stored in usage rows.
Install @alhwyn/convex-gmi-cloud, register the component in convex/convex.config.ts using app.use(gmiCloud), and set GMI_CLOUD_API_KEY with npx convex env set. Instantiate GmiCloud(components.gmiCloud) in your backend file and call gmi.chat() from a Convex action. The API key stays server-side and is never exposed to clients.
When calling gmi.submitJob(), pass an onComplete option with a mutation reference that accepts { jobId: v.string(), status: v.string() }. The GMI Cloud component schedules the callback exactly once after the job reaches a terminal state. An error in the callback does not revert the job's completed status.
The @alhwyn/convex-gmi-cloud component moves jobs through pending, success, failed, and timeout states. Successful jobs store GMI's full outcome including generated media URLs. Network errors, HTTP 429s, and 5xx responses are retried automatically; other HTTP errors fail the job immediately. The default timeout is 15 minutes and can be set between 1 second and 24 hours.
No. The @alhwyn/convex-gmi-cloud component records token counts, latency, and status in usage rows but does not store prompt text, message content, or credentials. API keys are absent from job documents, though dashboard operators with access to private scheduler arguments can inspect them there.
The GMI Cloud component caches model list responses per API credential using a SHA-256 fingerprint as the cache key. The default TTL is 5 minutes and can be set up to one day via the ttlMs option. Call gmi.listModels(ctx, { forceRefresh: true }) to bypass the cache. Failed refreshes preserve the previous cached entry.
In the @alhwyn/convex-gmi-cloud component, userId should always be derived from ctx.auth.getUserIdentity() inside an authenticated Convex action or query. Omitting userId from gmi.usage() or gmi.usageTotals() returns global data, which the README recommends restricting to trusted internal callers only. Authentication and access control remain the responsibility of your application.
The @alhwyn/convex-gmi-cloud component does not automatically retry job submissions. A lost HTTP response may leave an upstream job running that cannot be tracked or recovered. Provider-side idempotency and automatic cancellation are not provided, so your application should handle submission errors explicitly.