---
title: "Let a visitor try once"
description: "Let a signed-out visitor start one generation before they sign up: guest jobs run free under the app-wide limit, count per browser, and move to the new account's workspace at sign-up."
canonical_url: "https://nuxt-backend.dev/docs/build/ai/jobs/guests"
---
# Let a visitor try once

> Let a signed-out visitor start one generation before they sign up: guest jobs run free under the app-wide limit, count per browser, and move to the new account's workspace at sign-up.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: experimental

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- **You get:** one free generation for a visitor before sign-up, its result waiting in their workspace once they sign up.
- **Powered by:** the job queue, the bot check (`verifyHuman`) and an HttpOnly cookie per browser.
- **The package adds:** guest jobs that hold no credits, a count per visitor, the guest rank in the line, and the claim at sign-up.

Guest jobs join the same queue as everyone else's ([Run generation jobs](https://nuxt-backend.dev/docs/build/ai/jobs)), at the guest rank: after every tier, never in a dedicated slot, and never counted against a workspace's `perOwner` or budget ([Give plans priority in the queue](https://nuxt-backend.dev/docs/build/ai/jobs/priority)). The queue's `guest: { perVisitor }` option and a kind's `guest: true` turn them on.

The fastest way to show what your app does is to let people use it before they sign up. With `guest: { perVisitor: 1 }` on the queue and `guest: true` on a job, a signed-out visitor can start one job of that kind:

```ts [backend/jobs.ts]
import { defineJobQueue } from 'nuxt-backend/ai'
import { components } from './_generated/api'
import { ai } from './ai'

export const jobs = defineJobQueue(components, {
  ai,
  guest: { perVisitor: 1 },
})
```

```ts [backend/strips.ts]
import { verifyHuman } from 'nuxt-backend/functions'
import { mutation } from './_generated/server'

export const preview = jobs.define({
  meter: 'credits',
  cost: 10,
  guest: true,
  args: { stripId: v.id('strips'), idea: v.string(), panels: v.number() },
  handler: async (job, args) => { /* the same steps as render, with two panels */ },
})

export const tryOnce = mutation({
  args: { idea: v.string(), proof: v.string() },
  handler: async (ctx, { idea, proof }) => {
    await verifyHuman(ctx, proof, { action: 'try-once' })
    const stripId = await ctx.db.insert('strips', { idea })
    const { jobId } = await jobs.enqueue(ctx, internal.strips.preview, { stripId, idea, panels: 2 })
    await ctx.db.patch('strips', stripId, { jobId })
    return stripId
  },
})
```

The page asks for the proof right before the call, and names no subject, so the proof is bound to the browser:

```vue [app/components/TryOnce.vue]
<script setup lang="ts">
import { api } from '#backend/api'

const tryOnce = useMutation(api.strips.tryOnce)
const { token } = useHumanCheck()

async function submit(idea: string) {
  return await tryOnce({ idea, proof: await token('try-once') })
}
</script>
```

- **A guest job runs free:** with no account there are no credits, so the app pays, and the job holds nothing. It counts against the `aiGlobal` limit, the window shared by everything the app pays for, so a flood of visitors cannot run up your gateway bill. It allows 300 an hour across the deployment by default; set it like any limit in [`setupRateLimiter`](https://nuxt-backend.dev/docs/ship/security/rate-limits). `defineJobQueue({ guest })` refuses a `setupAi` without a `rateLimiter`.
- **The visitor is a browser,** identified by an HttpOnly cookie the package sets on the first try. `token(action)` with no subject asks the Nuxt server's `/api/human-proof` route, which sets the cookie (`__Host-` over HTTPS, signed with `PROTECTION_PROOF_SECRET`, kept a year) and binds the proof to that visitor; `verifyHuman` hands the visitor to `jobs.enqueue` in the same mutation. `perVisitor` counts jobs per cookie: the ones that wait, run or are done, since a failed or canceled one gives its try back. A done job's try stays used for the cookie's year: the queue keeps a count per visitor after the job's own record is deleted, 30 days after it ends. The bot check you pass to `verifyHuman` keeps scripts out. Clearing cookies gets someone a second try, which the `aiGlobal` limit and the bot check bound.
- **Sign-up claims the result.** When the visitor signs up in the same browser, their guest jobs and the rows that name them move to the new account's workspace, so the strip is waiting in their studio. A claimed job that has not started yet still runs as a guest job, and never counts against the workspace's `perOwner` or budget. Your rows join the claim through `setupAi({ guest: { claim } })`, a mutation that receives the guest's job ids and the new workspace.

Keep the guest's job small, two panels where a member gets six, and put the sign-up prompt beside its result.

## Move your rows at sign-up

The auth proxy forwards the visitor cookie with the sign-up request, and the account that request creates claims the visitor's jobs no account has claimed yet. The first sign-up in that browser takes them; a later one takes nothing, and the try stays used. Once the account's first session has made its workspace, the queue moves the jobs to it (to the account itself under `billTo: 'user'`) and runs your `claim`:

```ts [backend/ai.ts]
import { setupAi } from 'nuxt-backend/ai'
import { components, internal } from './_generated/api'
import { billing } from './billing'
import { rateLimiter } from './rateLimiter'

export const ai = setupAi(components, {
  billing,
  rateLimiter,
  guest: { claim: internal.strips.claimGuest },
})
```

```ts [backend/strips.ts]
export const claimGuest = internalMutation({
  args: { jobIds: v.array(v.string()), workspaceId: v.string(), userId: v.string() },
  handler: async (ctx, { jobIds, workspaceId }) => {
    for (const jobId of jobIds) {
      const strip = await ctx.db.query('strips').withIndex('by_jobId', q => q.eq('jobId', jobId)).unique()
      if (strip) await ctx.db.patch('strips', strip._id, { workspaceId })
    }
  },
})
```

Only the signed cookie claims anything. A visitor's id alone, a cookie signed for another deployment, or one whose signature does not hold claims nothing. Over HTTPS only the `__Host-` cookie counts, so a cookie planted from a sibling subdomain or over plain HTTP claims nothing either. A `claim` that throws rolls back on its own and is logged as `ai.guest_claim_failed`; the jobs are the account's all the same.

## Who reads a guest job

`useJob` and `getJob` answer signed-in callers only. Before sign-up, nobody reads a guest job but an administrator, who finds it in the [Queue tab](https://nuxt-backend.dev/docs/build/ai/jobs/operate) marked Guest. Show the visitor what your steps write to your own rows, such as the strip's panels, and read the job with `useJob` once they have signed up: the claim makes it theirs.

## When a visitor is refused

<table>
<thead>
  <tr>
    <th>
      What happens
    </th>
    
    <th>
      Refusal
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The browser has used its tries
    </td>
    
    <td>
      <code>
        unauthenticated
      </code>
      
      : ask them to sign up
    </td>
  </tr>
  
  <tr>
    <td>
      The kind has no <code>
        guest: true
      </code>
      
      , the queue no <code>
        guest
      </code>
      
      , or the proof names no browser
    </td>
    
    <td>
      <code>
        unauthenticated
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      The <code>
        aiGlobal
      </code>
      
       window is spent
    </td>
    
    <td>
      <code>
        rate_limited
      </code>
      
       with <code>
        limit: 'aiGlobal'
      </code>
      
       and <code>
        retryAfter
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      The bot check failed
    </td>
    
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        bot_check
      </code>
      
      , from <code>
        verifyHuman
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pause_ai
      </code>
      
       is on
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , as for every job
    </td>
  </tr>
</tbody>
</table>

The cookie and the proof need `PROTECTION_PROOF_SECRET` on the deployment and on the Nuxt server, and a server that signs proofs: the dev server, and a server on Vercel, where BotID runs. Off Vercel with the challenge keys alone, no proof names a visitor, so guests are refused ([Stop bots](https://nuxt-backend.dev/docs/build/auth/sign-in/bots)).

## Related

- [Run generation jobs](https://nuxt-backend.dev/docs/build/ai/jobs): the queue guest jobs join.
- [Give plans priority in the queue](https://nuxt-backend.dev/docs/build/ai/jobs/priority): where guest jobs rank.
- [Stop bots](https://nuxt-backend.dev/docs/build/auth/sign-in/bots): the bot check `verifyHuman` runs.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
