Skip to content

outputType Not Supported When Using Agent with ai-sdk/anthropic #185

@actuallyzefe

Description

@actuallyzefe

Please read this first

  • Have you read the docs? Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues. ✅

Describe the bug

on Agent Extensions - AI SDK

When using an agent with the @ai-sdk/anthropic provider, setting the outputType option results in an error instead of formatting the output as expected. The agent throws the following error:

{
  "error": "Error: Invalid output type"
}

And in @ai-sdk/[email protected] is working but it fall to loop and here is the console.log output:

{
  "content": [
    {
      "type": "text",
      "text": "{\"capital\":\"Berlin\",\"country\":\"Germany\"}"
    }
  ],
  "finishReason": "stop",
  "usage": {
    "inputTokens": 430,
    "outputTokens": 50,
    "totalTokens": 480,
    "cachedInputTokens": 0
  },
  "request": {
    "body": {
      "model": "claude-3-7-sonnet-20250219",
      "max_tokens": 4096,
      "system": [
        {
          "type": "text",
          "text": "You are a helpful assistant."
        }
      ],
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "What is the capital of Germany?"
            }
          ]
        }
      ],
      "tools": [
        {
          "name": "json",
          "description": "Respond with a JSON object.",
          "input_schema": {
            "type": "object",
            "properties": {
              "capital": {
                "type": "string"
              },
              "country": {
                "type": "string"
              }
            },
            "required": ["capital", "country"],
            "additionalProperties": false,
            "$schema": "http://json-schema.org/draft-07/schema#"
          }
        }
      ],
      "tool_choice": {
        "type": "tool",
        "name": "json"
      }
    }
  },
  "response": {
    "id": "msg_01BW6WewTgJy1gvFRbo5i7pj",
    "modelId": "claude-3-7-sonnet-20250219",
    "body": {
      "id": "msg_01BW6WewTgJy1gvFRbo5i7pj",
      "type": "message",
      "role": "assistant",
      "model": "claude-3-7-sonnet-20250219",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_012AH8c9JbrY3EzQRdJWRLD1",
          "name": "json",
          "input": {
            "capital": "Berlin",
            "country": "Germany"
          }
        }
      ],
      "stop_reason": "tool_use",
      "stop_sequence": null,
      "usage": {
        "input_tokens": 430,
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "output_tokens": 50,
        "service_tier": "standard"
      }
    }
  },
  "warnings": [],
  "providerMetadata": {
    "anthropic": {
      "cacheCreationInputTokens": 0
    }
  }
}

Debug information

  • Agents SDK version: v0.0.10
  • Runtime environment Node.js 22.16.0
  • @ai-sdk/anthropic: 1.2.12

Repro steps

import { anthropic } from '@ai-sdk/anthropic';
import { aisdk } from '@openai/agents-extensions';

const model = aisdk(anthropic('claude-3-7-sonnet-20250219'));

function agent() {
  const agent = new Agent({
    name: 'Test Agent',
    instructions: `You are a helpful assistant.`,
    model,
    outputType: z.object({
      message: z.string(),
    }),
  });
}

Expected behavior

An appropriate warning logs could be useful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions