use strict compatibility in createOpenAI

When using createOpenAI() from @ai-sdk/openai  w/o provider override,
token usage info is sent as 0 or null. Enforcing compatibilty fixes
this.
This commit is contained in:
Ramnique Singh 2025-08-14 21:15:56 +05:30
parent a0bb7e6404
commit bf29af3083
2 changed files with 4 additions and 2 deletions

View file

@ -1,5 +1,5 @@
// External dependencies // External dependencies
import { Agent, AgentInputItem, run, Tool } from "@openai/agents"; import { Agent, AgentInputItem, run, RunRawModelStreamEvent, Tool } from "@openai/agents";
import { RECOMMENDED_PROMPT_PREFIX } from "@openai/agents-core/extensions"; import { RECOMMENDED_PROMPT_PREFIX } from "@openai/agents-core/extensions";
import { aisdk } from "@openai/agents-extensions"; import { aisdk } from "@openai/agents-extensions";
import { createOpenAI } from "@ai-sdk/openai"; import { createOpenAI } from "@ai-sdk/openai";
@ -78,6 +78,7 @@ interface AgentState {
const openai = createOpenAI({ const openai = createOpenAI({
apiKey: PROVIDER_API_KEY, apiKey: PROVIDER_API_KEY,
baseURL: PROVIDER_BASE_URL, baseURL: PROVIDER_BASE_URL,
compatibility: "strict",
}); });
const ZOutMessage = z.union([ const ZOutMessage = z.union([
@ -734,7 +735,7 @@ function maybeInjectGiveUpControlInstructions(
// Handle raw model stream events // Handle raw model stream events
async function* handleRawModelStreamEvent( async function* handleRawModelStreamEvent(
event: any, event: RunRawModelStreamEvent,
agentConfig: Record<string, z.infer<typeof WorkflowAgent>>, agentConfig: Record<string, z.infer<typeof WorkflowAgent>>,
agentName: string, agentName: string,
turnMsgs: z.infer<typeof Message>[], turnMsgs: z.infer<typeof Message>[],

View file

@ -34,6 +34,7 @@ const SYSTEM_PROMPT = [
const openai = createOpenAI({ const openai = createOpenAI({
apiKey: PROVIDER_API_KEY, apiKey: PROVIDER_API_KEY,
baseURL: PROVIDER_BASE_URL, baseURL: PROVIDER_BASE_URL,
compatibility: "strict",
}); });
const ZTextEvent = z.object({ const ZTextEvent = z.object({