Every Instructor extraction in a codebase flows through one object: the patched client built with instructor.from_openai. Point that client at a gateway and every extraction inherits the setup.
client = instructor.from_openai(
OpenAI(
base_url="https://api.nrouter.ai/v1",
api_key=os.environ["NROUTER_API_KEY"],
timeout=30.0,
max_retries=2,
)
)
What stays: the Pydantic models, response_model, and Instructor's validation retries — when an output fails the schema, the model is asked again. That fixes the answer.
What the gateway adds: fallbacks for when the call itself fails (named in extra_body, or nrouter/auto with a quality, balanced or cost preference), exact-match caching for repeat extractions, and headers on every response — x-nr-request-id, x-nr-model, x-nr-cost-status, x-nr-request-cost. Guardrail blocks surface as BadRequestError; rate limits as RateLimitError.
Full guide: https://nrouter.ai/docs/frameworks/instructor