0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Putting Instructor's Patched Client Behind a Gateway

0
Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?