Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions js/plugins/anthropic/src/runner/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,19 @@ export class BetaRunner extends BaseRunner<BetaRunnerTypes> {
topK,
apiVersion: _1,
thinking: _2,
maxOutputTokens,
stopSequences,
version,
apiKey,
...restConfig
Comment thread
ifielker marked this conversation as resolved.
} = request.config ?? {};

const body = {
model: mappedModelName,
max_tokens:
request.config?.maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
max_tokens: maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
messages,
system: system as BetaTextBlockParam[],
stop_sequences: request.config?.stopSequences,
stop_sequences: stopSequences,
temperature: request.config?.temperature,
top_k: topK,
top_p: topP,
Expand Down Expand Up @@ -381,17 +384,20 @@ export class BetaRunner extends BaseRunner<BetaRunnerTypes> {
topK,
apiVersion: _1,
thinking: _2,
maxOutputTokens,
stopSequences,
version,
apiKey,
...restConfig
Comment thread
ifielker marked this conversation as resolved.
} = request.config ?? {};

const body = {
model: mappedModelName,
max_tokens:
request.config?.maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
max_tokens: maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
messages,
stream: true,
system: system as BetaTextBlockParam[],
stop_sequences: request.config?.stopSequences,
stop_sequences: stopSequences,
temperature: request.config?.temperature,
top_k: topK,
top_p: topP,
Expand Down
13 changes: 10 additions & 3 deletions js/plugins/anthropic/src/runner/stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,19 @@ export class Runner extends BaseRunner<RunnerTypes> {
topK,
apiVersion: _1,
thinking: _2,
maxOutputTokens,
stopSequences,
version,
apiKey,
...restConfig
Comment thread
ifielker marked this conversation as resolved.
} = request.config ?? {};

const body: MessageCreateParamsNonStreaming = {
model: mappedModelName,
max_tokens:
request.config?.maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
max_tokens: maxOutputTokens ?? this.DEFAULT_MAX_OUTPUT_TOKENS,
messages,
system: system as TextBlockParam[],
stop_sequences: request.config?.stopSequences,
stop_sequences: stopSequences,
temperature: request.config?.temperature,
top_k: topK,
top_p: topP,
Expand Down Expand Up @@ -294,6 +297,10 @@ export class Runner extends BaseRunner<RunnerTypes> {
topK,
apiVersion: _1,
thinking: _2,
maxOutputTokens,
stopSequences,
version,
apiKey,
...restConfig
Comment thread
ifielker marked this conversation as resolved.
} = request.config ?? {};

Expand Down
36 changes: 36 additions & 0 deletions js/plugins/anthropic/tests/beta_runner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,42 @@ describe('BetaRunner', () => {
);
});

it('should not leak maxOutputTokens, stopSequences, version, or apiKey into the request body', () => {
const mockClient = createMockAnthropicClient();
const runner = new BetaRunner({
name: 'claude-3-5-haiku',
client: mockClient as Anthropic,
}) as any;

const body = runner.toAnthropicRequestBody(
'claude-3-5-haiku',
{
messages: [],
config: {
maxOutputTokens: 100,
stopSequences: ['END'],
version: 'claude-3-5-haiku-custom',
apiKey: 'fake-api-key',
temperature: 0.5,
},
} satisfies any,
false
);

assert.deepStrictEqual(body, {
model: 'claude-3-5-haiku-custom',
max_tokens: 100,
messages: [],
stop_sequences: ['END'],
temperature: 0.5,
betas: [
'files-api-2025-04-14',
'effort-2025-11-24',
'structured-outputs-2025-11-13',
],
});
});

it('should throw for unsupported mcp tool use blocks', () => {
const mockClient = createMockAnthropicClient();
const runner = new BetaRunner({
Expand Down
27 changes: 27 additions & 0 deletions js/plugins/anthropic/tests/stable_runner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,33 @@ describe('Runner request bodies and error branches', () => {
assert.deepStrictEqual(body.thinking, { type: 'disabled' });
});

it('should not leak maxOutputTokens, stopSequences, version, or apiKey into the request body', () => {
const mockClient = createMockAnthropicClient();
const runner = new Runner({
name: 'claude-3-5-haiku',
client: mockClient,
}) as Runner & RunnerProtectedMethods;

const body = runner['toAnthropicRequestBody']('claude-3-5-haiku', {
messages: [],
config: {
maxOutputTokens: 100,
stopSequences: ['END'],
version: 'claude-3-5-haiku-custom',
apiKey: 'fake-api-key',
temperature: 0.5,
},
} as unknown as GenerateRequest<typeof AnthropicConfigSchema>);

assert.deepStrictEqual(body, {
model: 'claude-3-5-haiku-custom',
max_tokens: 100,
messages: [],
stop_sequences: ['END'],
temperature: 0.5,
});
});

it('should throw descriptive errors for missing tool refs', () => {
const mockClient = createMockAnthropicClient();
const runner = new Runner({
Expand Down
Loading