For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
  • Gateway
      • OpenAI SDK
      • Instructor
      • Anthropic SDK
      • Google GenAI
      • LiteLLM
      • RubyLLM
      • Vertex AI
      • AWS Bedrock
      • Cohere
      • Groq
      • Mistral AI
      • Ollama
      • Watsonx
      • Together AI
      • Aleph Alpha
      • HuggingFace
      • Replicate
      • SageMaker
      • Respan API
  • Others
  • Migrating
    • Braintrust
    • Portkey
    • Langfuse
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Switch models
GatewayLLM SDKs

Instructor (gateway)

Was this page helpful?
Previous

Anthropic SDK (gateway)

Next
Built with

Route Instructor’s underlying OpenAI-compatible LLM calls through the Respan gateway to use 250+ models from different providers. Only your Respan API key is needed - no separate provider key is required.

Setup

1

Install packages

$pip install respan-tracing respan-instrumentation-instructor instructor openai
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export RESPAN_BASE_URL="https://api.respan.ai/api"

No OPENAI_API_KEY is needed when the request is routed through the Respan gateway.

3

Point Instructor to the Respan gateway

1import os
2from typing import TypedDict
3
4import instructor
5from respan_tracing import RespanTelemetry, workflow
6from respan_tracing.exporters import propagate_attributes
7from respan_instrumentation_instructor import InstructorInstrumentor
8
9respan_api_key = os.environ["RESPAN_API_KEY"]
10respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")
11
12telemetry = RespanTelemetry(
13 api_key=respan_api_key,
14 base_url=respan_base_url,
15 app_name="instructor-gateway",
16 is_auto_instrument=False,
17)
18InstructorInstrumentor().activate()
19
20client = instructor.from_provider(
21 "openai/gpt-4o-mini",
22 api_key=respan_api_key,
23 base_url=respan_base_url,
24 mode=instructor.Mode.TOOLS,
25)
26
27
28class Person(TypedDict):
29 name: str
30 role: str
31
32
33@workflow(name="person_extraction")
34def extract_person() -> Person:
35 return client.create(
36 response_model=Person,
37 messages=[
38 {
39 "role": "user",
40 "content": "Grace Hopper was a pioneering computer scientist.",
41 }
42 ],
43 )
44
45
46with propagate_attributes(
47 thread_identifier="instructor_gateway_person_extraction",
48 metadata={"integration": "instructor", "route": "gateway"},
49):
50 person = extract_person()
51 print(dict(person))
52
53telemetry.flush()

Switch models

Change the model string passed to instructor.from_provider to use another gateway model through the same OpenAI-compatible endpoint.

1client = instructor.from_provider(
2 "openai/claude-sonnet-4-5-20250929",
3 api_key=os.environ["RESPAN_API_KEY"],
4 base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
5 mode=instructor.Mode.TOOLS,
6)

See the full model list.