Skip to content

Commit

Permalink
Merge pull request #9 from milancermak/fix/api-key-printout
Browse files Browse the repository at this point in the history
fix: no apiKey in logs
  • Loading branch information
ponderingdemocritus authored Jan 14, 2025
2 parents b6a9e8c + 61e0e63 commit ea669b5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/core/src/core/llm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ export class LLMClient {
});
}

// obfuscate the API key when logging
toJSON() {
let maskedApiKey = this.config.apiKey.slice(0, 7) + "*".repeat(3);

return {
...this,
config: {
...this.config,
apiKey: maskedApiKey,
},
anthropic: this.anthropic && {
...this.anthropic,
apiKey: maskedApiKey,
_options: {
// @ts-ignore
...this.anthropic._options,
apiKey: maskedApiKey,
},
},
};
}

[Symbol.for("nodejs.util.inspect.custom")]() {
return this.toJSON();
}

public async complete(prompt: string): Promise<LLMResponse> {
let lastError: Error | null = null;

Expand Down

0 comments on commit ea669b5

Please sign in to comment.