Files
llmapikey/lib/openrouter/create-key-request-body.js
tiennm99 d0fdcb4041 feat(keys): create minted OpenRouter keys in a configured workspace
Pass create-key workspace_id (from OPENROUTER_WORKSPACE_ID, defaulting to the
project workspace) so minted keys land in the intended workspace instead of the
management key's default. Rename key to non-PII llmapikey/gh-<id>.

- buildCreateKeyBody emits workspace_id only when set (omission keeps default).
- createKey threads workspaceId; mintAndPersist sources it from env.
- Test asserts workspace_id presence/omission; document the new env var.
2026-06-14 12:40:03 +07:00

24 lines
904 B
JavaScript

/**
* Pure request-body shaping for the OpenRouter create-key call. No I/O, no
* `server-only` guard — so it is unit-testable under plain node.
*
* Fields are snake_case per the OpenRouter API ref (`limit_reset`,
* `include_byok_in_limit`, `expires_at`, `workspace_id`).
*
* @param {{ name: string, limitUsd: number, resetPeriod: string, includeByok: boolean, expiresAt: string, workspaceId?: string }} params
* @returns {Record<string, unknown>}
*/
export function buildCreateKeyBody({ name, limitUsd, resetPeriod, includeByok, expiresAt, workspaceId }) {
const body = {
name,
limit: limitUsd,
limit_reset: resetPeriod,
include_byok_in_limit: includeByok,
expires_at: expiresAt,
};
// Place the key in a specific workspace; omitted → OpenRouter uses the
// management key's default workspace.
if (workspaceId) body.workspace_id = workspaceId;
return body;
}