ai icon indicating copy to clipboard operation
ai copied to clipboard

workers-ai-provider does not handle Response API

Open harshil1712 opened this issue 3 months ago • 2 comments

The workers-ai-provider package doesn't handle the response API for the new GPT OSS models.

  • When passing the input and instructions parameters needed for these models, the following error is returned:

Example code:

const aiResponse = await generateText({
    model: workersAi('@cf/openai/gpt-oss-20b'),
    input: message,
    instructions: 'You are a helpful assistant',
  });

Error:

✘ [ERROR] Error in conversation: InvalidPromptError [AI_InvalidPromptError]: Invalid prompt: prompt or messages must be defined

      at standardizePrompt
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/prompt/standardize-prompt.ts:23:11)
      at generateText
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:265:31)
      at workersAiAiSdk
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:59:28)
      at SiriAssistant.handleConversation
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:144:32)
      at async SiriAssistant._tryCatch
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/agents/src/index.ts:805:14)
      at async SiriAssistant.fetch
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/partyserver/src/index.ts:308:16)
  {
    cause: undefined,
    prompt: { system: undefined, prompt: undefined, messages:
  undefined },
    Symbol(vercel.ai.error): true,
    Symbol(vercel.ai.error.AI_InvalidPromptError): true
  }
  • If passing messages and/or prompt (as per the error message), a new error is thrown. Example code:
const aiResponse = await generateText({
    model: workersAi('@cf/openai/gpt-oss-20b'),
    messages: [{ role: 'user', content: message }],
  });

Error:

✘ [ERROR] Error in conversation: InferenceUpstreamError [AiError]: 5006: Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'input', required properties at '/' are 'requests'

      at Ai._parseError (cloudflare-internal:ai-api:212:24)
      at async Ai.run (cloudflare-internal:ai-api:190:19)
      at async WorkersAIChatLanguageModel.doGenerate
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/workers-ai-provider/src/workersai-chat-language-model.ts:145:18)
      at async fn
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:382:32)
      at null.<anonymous> (async
  file:///Users/harshil/projects/voice-assistant-worker/.wrangler/tmp/dev-Q4WtKi/index.js:50184:22)
      at async _retryWithExponentialBackoff
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12)
      at async fn
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:338:34)
      at null.<anonymous> (async
  file:///Users/harshil/projects/voice-assistant-worker/.wrangler/tmp/dev-Q4WtKi/index.js:50184:22)
      at async generateText
  (file:///Users/harshil/projects/voice-assistant-worker/node_modules/ai/src/generate-text/generate-text.ts:274:12)
      at async workersAiAiSdk
  (file:///Users/harshil/projects/voice-assistant-worker/src/index.ts:59:22)

harshil1712 avatar Sep 03 '25 21:09 harshil1712