Skip to Content
prxy.monster v1 is in early access. See what shipped →
IntegrationsUsing prxy.monster with Instructor

Using prxy.monster with Instructor

Instructor  (and instructor-js) is a structured-output library that wraps the OpenAI / Anthropic clients. Because Instructor patches existing clients rather than reimplementing them, the integration is the same as the underlying SDK — set the base URL on the client you pass in.

Install

pip install instructor openai pydantic

Configure

import instructor from openai import OpenAI from pydantic import BaseModel client = instructor.from_openai( OpenAI( base_url="https://api.prxy.monster/v1", api_key="prxy_live_xxxxxxxxxxxxxxxxxxxxxxxx", ) ) class User(BaseModel): name: str age: int user = client.chat.completions.create( model="gpt-4o", response_model=User, messages=[{"role": "user", "content": "John is 30 years old"}], )

Code change

The base_url / baseURL arg on the underlying client is the only diff.

You can also use env vars (OPENAI_BASE_URL=https://api.prxy.monster/v1) and pass OpenAI() with no args.

Verify

curl https://api.prxy.monster/health

What you get — extra value for Instructor users

  • Semantic cache wins big here — extracting the same schema from similar inputs (invoice line items, contact records, log entries) hits cache often.
  • Cost guards prevent runaway extraction loops on bad data.
  • Pattern memory — extraction patterns (“when input looks like X, schema fills like Y”) get learned.

For batch extraction:

PRXY_PIPE=exact-cache,semantic-cache,cost-guard,patterns

For interactive extraction:

PRXY_PIPE=semantic-cache,patterns,cost-guard

Anthropic-backed Instructor

instructor.from_anthropic(Anthropic(base_url='https://api.prxy.monster', ...)) works the same way.

Common issues

  • Retry loops on validation failure — Instructor will retry the LLM call up to N times if the response doesn’t validate. Each retry counts against your prxy.monster cost-guard budget if enabled. Cap retries at 2-3 for production.
  • Streaming structured output (partial_response_model) — pass-through.

Full example

Adapt examples/openai-quickstart  — wrap the OpenAI() client in instructor.from_openai(...) and add a Pydantic schema.

Instructor wraps the official SDK clients, so any base-URL change you’d make on the underlying client also applies here. Verify with the Instructor docs  for your installed version.

Last updated on