prxy.monster API-key BYOK is live. Start free

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

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

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.