Instructor
Prerequisite
To start using Instructor with Orq, you need an API Key ready within your Orq.ai account.
To setup your API key, see API keys & Endpoints.
Using Orq.ai as Proxy
Using Instructor , set the API Base to the Orq.ai Proxy to feed calls through our API without changing any other part of your code.
Using the Orq.ai Proxy, you benefit from the Platform Traces, Cost and Usage Monitoring, keeping full compatibility and unified API with all models while using the Instructor SDK..
base_url:
https://api.orq.ai/v2/proxy
api_key: Your Orq API key
import instructor
from pydantic import BaseModel
from openai import OpenAI
import os
# Define your desired output structure
class UserInfo(BaseModel):
name: str
age: int
# Patch the OpenAI client
client = instructor.from_openai(OpenAI(
base_url="https://api.orq.ai/v2/proxy",
api_key=os.getenv("ORQ_API_KEY")))
# Extract structured data from natural language
user_info = client.chat.completions.create(
model="openai/gpt-4o-mini",
response_model=UserInfo,
messages=[{"role": "user", "content": "John Doe is 30 years old."}],
)
print(user_info.name)
#> John Doe
print(user_info.age)
#> 30
Updated about 5 hours ago