📡 fix: Respect Custom Endpoint Stream Usage Opt-In (#13237)

This commit is contained in:
Danny Avila 2026-05-21 15:39:57 -04:00 committed by GitHub
parent 05a3d1ed81
commit cfe0f9f7f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -205,6 +205,39 @@ beforeEach(() => {
jest.clearAllMocks();
});
// ---------------------------------------------------------------------------
// Suite: custom endpoint stream usage defaults
// ---------------------------------------------------------------------------
describe('custom endpoint stream usage defaults', () => {
it('disables streamUsage by default for OpenAI-compatible custom endpoints', async () => {
const agents = await callAndCapture({
agents: [makeAgent({ endpoint: 'LiteLLM' })],
});
const clientOptions = agents[0].clientOptions as Record<string, unknown>;
expect(clientOptions.streamUsage).toBe(false);
expect(clientOptions.usage).toBe(true);
});
it('respects explicit streamUsage from endpoint-resolved model parameters', async () => {
const agents = await callAndCapture({
agents: [
makeAgent({
endpoint: 'LiteLLM',
model_parameters: {
model: 'gpt-4o',
streamUsage: true,
},
}),
],
});
const clientOptions = agents[0].clientOptions as Record<string, unknown>;
expect(clientOptions.streamUsage).toBe(true);
expect(clientOptions.usage).toBe(true);
});
});
// ---------------------------------------------------------------------------
// Suite 1: reserveRatio
// ---------------------------------------------------------------------------

View file

@ -804,6 +804,10 @@ export async function createRun({
);
const modelParameters = normalizeAgentModelParameters(agent.model_parameters);
const hasExplicitStreamUsage = Object.prototype.hasOwnProperty.call(
modelParameters ?? {},
'streamUsage',
);
const llmConfig = Object.assign(
{
provider,
@ -847,7 +851,9 @@ export async function createRun({
customProviders.has(agent.provider) ||
(agent.provider === Providers.OPENAI && agent.endpoint !== agent.provider)
) {
llmConfig.streamUsage = false;
if (!hasExplicitStreamUsage) {
llmConfig.streamUsage = false;
}
llmConfig.usage = true;
}