Lemline documentation Help

How to use API keys

Declare the key in use.secrets and supply its value through your Lemline secrets configuration.

Prepare the examples

Complete the SQLite setup. The examples call the partner route of the tutorial shop, GET /partner/stock. It answers HTTP 401 without credentials and HTTP 403 with a wrong value, and lists every request it received, with its headers and query, under Requests on the shop page. Start it from the root of the Lemline source checkout:

docker compose -f examples/tutorial-services/compose.yaml up -d

Run the other commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. The worker reads secrets from its environment when it starts, so each example below stops the worker with Ctrl+C, exports the value, and starts the worker again in the same terminal. Run the definition and instance commands from a second terminal.

Export the shop's demo values, demo-api-key as apiKey and demo-token as apiToken, and start the worker:

export apiKey='demo-api-key' export apiToken='demo-token' bin/lemline listen --debug

Send a key in a header

Set the header required by your service in with.headers. The expression resolves the secret when the task runs.

document: dsl: '1.0.3' namespace: examples name: http-request-with-api-key version: '1.0.0' use: secrets: - apiKey do: - getPartnerStock: call: http with: method: get endpoint: http://127.0.0.1:8787/partner/stock headers: X-API-Key: ${ $secrets.apiKey }

Save it as http-request-with-api-key.yaml:

bin/lemline definition post -f http-request-with-api-key.yaml bin/lemline instance start examples http-request-with-api-key

Expect {"sku":"SKU-1","available":100,"authenticatedWith":"api-key-header"}. The shop lists the x-api-key header it received.

Send a key in a query parameter

Use with.query if the service requires a query parameter. Headers are preferable where the service supports them because URLs often appear in access logs.

document: dsl: '1.0.3' namespace: examples name: http-request-with-query-key version: '1.0.0' use: secrets: - apiKey do: - getPartnerStock: call: http with: method: get endpoint: http://127.0.0.1:8787/partner/stock query: api_key: ${ $secrets.apiKey }

Save it as http-request-with-query-key.yaml:

bin/lemline definition post -f http-request-with-query-key.yaml bin/lemline instance start examples http-request-with-query-key

Expect {"sku":"SKU-1","available":100,"authenticatedWith":"api-key-query"}. The shop lists the request with api_key=demo-api-key in its query: the key also appears in the worker log line of the request URL.

Send a bearer token

For an API that expects Authorization: Bearer ..., use a named bearer authentication policy and reference it from with.endpoint.authentication.use.

document: dsl: '1.0.3' namespace: examples name: bearer-authentication version: '1.0.0' use: secrets: - apiToken authentications: partnerAuth: bearer: token: ${ $secrets.apiToken } do: - getPartnerStock: call: http with: method: get endpoint: uri: http://127.0.0.1:8787/partner/stock authentication: use: partnerAuth

Save it as bearer-authentication.yaml:

bin/lemline definition post -f bearer-authentication.yaml bin/lemline instance start examples bearer-authentication

Expect {"sku":"SKU-1","available":100,"authenticatedWith":"bearer"}. The shop lists the authorization header Bearer demo-token.

A missing or wrong value is the service's answer, not Lemline's. Stop the worker, export a wrong key, start the worker again and repeat the first example:

export apiKey='wrong-key' bin/lemline listen --debug
bin/lemline instance start examples http-request-with-api-key

The shop answers HTTP 403 and the instance faults with a communication error, status 403, titled HTTP 403: {"error":"Invalid credentials for api-key-header". Stop the shop when you are done:

docker compose -f examples/tutorial-services/compose.yaml down

See the Authentication Reference for policy placement and secret reuse.

25 November 2026