> For the complete documentation index, see [llms.txt](https://vampauth.gitbook.io/vampauth-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vampauth.gitbook.io/vampauth-docs/development/loader-macros.md).

# Runtime variables and helpers

Inside the script the loader executes, `VAMPAUTH` describes the current run. It isn't a live copy of your dashboard settings.

```lua
local auth = VAMPAUTH
print(auth.key_group or "No key group")
print(auth.keyless and "Keyless run" or "Keyed run")
```

The same context is passed as the script's first argument, so `local auth = ...` works at the top of the loaded script too. The context is read-only; assigning its fields or replacing `VAMPAUTH` raises an error.

| Value                      | Meaning                                                           |
| -------------------------- | ----------------------------------------------------------------- |
| `VAMPAUTH.key_group`       | Exact group name, or nil for ungrouped/keyless runs               |
| `VAMPAUTH.keyless`         | True for keyless access; false for a keyed run                    |
| `VAMPAUTH.expires_at`      | Unix time in **milliseconds**, or nil for lifetime/keyless access |
| `VAMPAUTH.lease_enabled`   | True when this keyed run uses session leases                      |
| `VAMPAUTH.is_active()`     | Boolean indicating whether the runtime is active                  |
| `VAMPAUTH.assert_active()` | Returns true while active; raises an error once inactive          |

A successful first-use admission activates the key before its expiry is exposed to the run. The standalone API uses an ISO expiry timestamp instead of milliseconds.

## Read the expiry

```lua
local auth = VAMPAUTH
if auth.expires_at then
    local expires = DateTime.fromUnixTimestampMillis(auth.expires_at)
    print("Key expires:", expires:ToIsoDate())
else
    print("This run has no key expiry.")
end
```

## Background work

```lua
local auth = VAMPAUTH

task.spawn(function()
    while auth.is_active() do
        -- Put one unit of background work here.
        task.wait(1)
    end
    -- Disconnect events and release this task's resources here.
end)

local function runProtectedAction()
    auth.assert_active()
    -- Continue with the action.
end
```

Check inside long-running loops, not just before starting them. The loader can cancel its root task, but a task you spawn needs its own exit path. Turn on loader leases for ongoing server authorization; with leases off, the helpers don't continuously revalidate the key.

## Next steps

* [Loader](/vampauth-docs/development/loader.md)
* [Sessions and concurrency](/vampauth-docs/development/sessions.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://vampauth.gitbook.io/vampauth-docs/development/loader-macros.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
