Skip to content


Because we've build everything on top of Pydantic, we automatically integrate seamlessly with FastAPI. This was by design to reduce the overhead of writing out a separate schema for your endoint.

import os

from fastapi import FastAPI
from pydantic import BaseModel

from mirascope.openai import OpenAICallParams, OpenAIExtractor


app = FastAPI()

class Book(BaseModel):
    title: str
    author: str

class BookRecommender(OpenAIExtractor[Book]):
    extract_schema: type[Book] = Book
    prompt_template = "Please recommend a {genre} book."

    genre: str

    call_params = OpenAICallParams(tool_choice="required")"/")
def root(book_recommender: BookRecommender) -> Book:
    """Generates a book based on provided `genre`."""
    return book_recommender.extract()