Use this file to discover all available pages before exploring further.
Structured Outputs ensure that models follow your supplied JSON schema. Portkey supports this for Anthropic models using a unified response_format interface.Define object schemas using Pydantic (Python) or Zod (JavaScript) to extract structured information from unstructured text.
This approach provides type hinting and automatic validation.
from portkey_ai import Portkeyfrom pydantic import BaseModelclass Step(BaseModel): explanation: str output: strclass MathReasoning(BaseModel): steps: list[Step] final_answer: strportkey = Portkey( api_key="PORTKEY_API_KEY")# Use .parse() for automatic parsingcompletion = portkey.chat.completions.parse( model="@anthropic-testing/claude-sonnet-4-6", messages=[ {"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."}, {"role": "user", "content": "how can I solve 8x + 7 = -23"} ], response_format=MathReasoning)print(completion.choices[0].message.parsed)