mirror of
https://github.com/tiennm99/llmapikey.git
synced 2026-08-08 08:22:11 +00:00
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.
24 lines
904 B
JavaScript
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;
|
|
}
|