> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtcreate.md).

# JWTCreate

Signs a payload struct and returns a compact JWS (signed JWT) token string.

## Method Signature

```
JWTCreate( payload, [key], [algorithm], [options] )
```

### Arguments

| Argument    | Type     | Required | Description                                                                                                          | Default |
| ----------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------- | ------- |
| `payload`   | `struct` | Yes      | Claims to encode in the token.                                                                                       |         |
| `key`       | `any`    | No       | Signing key — named key from the registry, HMAC secret, or PEM/JWK string. Optional when `defaultSigningKey` is set. | `null`  |
| `algorithm` | `string` | No       | Signing algorithm (e.g. `HS256`, `RS256`, `ES256`). Resolved from key metadata or `defaultAlgorithm` if omitted.     | `null`  |
| `options`   | `struct` | No       | `headers` (custom JOSE headers struct), `generateIat` (boolean), `generateJti` (boolean).                            | `{}`    |

### Returns

A compact JWS string of the form `<header>.<payload>.<signature>`.

## Examples

```javascript
// HMAC signing
token = jwtCreate( { sub: "u1", iss: "api" }, "my-32-byte-secret-goes-here!!!", "HS256" );

// RSA signing with a custom kid header
token = jwtCreate( { sub: "u1" }, privateKeyPem, "RS256", { headers: { kid: "rsa-v1" } } );

// Use a named key from the registry — algorithm resolved from key metadata
token = jwtCreate( { sub: "u1" }, "myapp-hmac" );

// Disable auto-generated iat for this call
token = jwtCreate( { sub: "u1", iat: specificDate }, secret, "HS256", { generateIat: false } );
```

## Related

* [JWTVerify()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtverify.md) — verify the token signature & claims
* [JWTDecode()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtdecode.md) — inspect headers/claims without verifying
* [JWTNew()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtnew.md) — fluent builder alternative
* [JWTRefresh()](/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtrefresh.md) — re-issue with fresh time claims
* [Signing (JWS) Guide](/boxlang-framework/modularity/jwt/signing-jws.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/modularity/jwt/reference/built-in-functions/jwtcreate.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
