vercel/ai · error · InvalidPromptError

Moonshot AI Partial Mode cannot be combined with JSON object

Error message

Moonshot AI Partial Mode cannot be combined with JSON object response format.

What it means

Moonshot AI Partial Mode (an incomplete assistant prefix message) is incompatible with a 'json_object' response format: the API cannot both continue a partial message and force JSON output. The converter throws InvalidPromptError when both are requested in the same call.

Source

Thrown at packages/moonshotai/src/convert-to-moonshotai-chat-messages.ts:303

            name: moonshotMessageOptions.name,
          }),
        });

        break;
      }

      case 'assistant': {
        if (moonshotMessageOptions?.partial === true) {
          if (index !== prompt.length - 1) {
            throw new InvalidPromptError({
              prompt,
              message:
                'Moonshot AI Partial Mode requires the partial assistant message to be the final message.',
            });
          }

          if (responseFormat?.type === 'json_object') {
            throw new InvalidPromptError({
              prompt,
              message:
                'Moonshot AI Partial Mode cannot be combined with JSON object response format.',
            });
          }
        }

        let text = '';
        let reasoning = '';
        const toolCalls: Array<{
          id: string;
          type: 'function';
          function: { name: string; arguments: string };
        }> = [];

        for (const part of content) {
          switch (part.type) {
            case 'text': {

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Remove partial: true from the assistant message when using JSON object response format.
  2. Drop the json_object response format if continuation of the partial message is what you need.
  3. If you need JSON from a continuation, post-process the continued text with a schema parser instead.
  4. Split into two calls: one to complete the partial message, then one with json_object.

Example fix

// before
{ responseFormat: { type: 'json_object' }, messages: [assistant('...', { partial: true })] }
// after
{ messages: [assistant('...')] } // or remove responseFormat
Defensive patterns

Strategy: validation

Validate before calling

function partialModeWithJson(messages: ModelMessage[], responseFormat?: { type: string }): boolean {
  const hasPartial = messages.some(m => m.role === 'assistant' && (m.providerOptions?.moonshot as any)?.partial === true);
  return hasPartial && responseFormat?.type === 'json_object';
}
if (partialModeWithJson(messages, responseFormat)) throw new Error('Partial Mode cannot be combined with json_object');

Try / catch

import { InvalidPromptError } from '@ai-sdk/provider';
try {
  await generateText({ model: moonshot(id), messages, /* responseFormat */ });
} catch (e) {
  if (InvalidPromptError.isInstance(e) && e.message.includes('cannot be combined')) {
    // retry without partial: true or without json_object
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling generateText/streamObject with responseFormat type 'json_object' while an assistant message in the prompt has providerOptions.moonshot.partial = true.

Common situations: Combining a continue-completion feature with structured JSON output; copying provider options between calls and leaving partial: true set when switching to generateObject.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/5062abe741750091. Report an issue: GitHub.