Use Instructor with Shannon
Patch an OpenAI client pointed at Shannon with Instructor and get Pydantic objects back from Shannon models, whole or streamed.
- Tested Nov 7, 2026
- OpenAI Chat Completions
- About 1 min
About Instructor
Instructor turns model answers into validated Pydantic objects: you pass a response_model and get typed data back, with retries when validation fails. It wraps the OpenAI client, so pointing that client at Shannon gives structured output from Shannon models.
What you need
- A Shannon API key
- Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Every snippet below follows your choice.
Set it up
-
Install Instructor
Shellpip install instructor openai -
Get a typed object back
Mode.TOOLSasks for the object through a tool call, which Shannon models support.Pythonimport instructor from openai import OpenAI from pydantic import BaseModel client = instructor.from_openai( OpenAI(base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY"), mode=instructor.Mode.TOOLS, ) class Cat(BaseModel): name: str colour: str age_years: int cat = client.chat.completions.create( model="Kimi-K3-uncensored-NVFP4", response_model=Cat, messages=[{"role": "user", "content": "Tom is a grey cat, 4 years old."}], ) print(cat) # name='Tom' colour='grey' age_years=4 -
Stream a partial object
Pythonfor partial in client.chat.completions.create_partial( model="Kimi-K3-uncensored-NVFP4", response_model=Cat, messages=[{"role": "user", "content": "Make up a cat: name, colour, age in years."}], ): print(partial)
Check that it works
Send: Run the first sample.
You should see: name='Tom' colour='grey' age_years=4
Models that fit Instructor
Every id below meets what Instructor needs. The first one is the default in the snippets.
| Model id | Context window | Max output | Image input |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Yes |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Yes |
shannon-3 | 196,608 | 65,536 | Yes |
shannon-coder-1 | 131,072 | 65,536 | No |
Good to know
Mode.TOOLSis the mode to use with Shannon; it relies on tool calls, which every model in the picker makes.- Wrap your own client with
from_openaias shown, so the base URL and key are the Shannon ones.
Tips
max_retries=2oncreatere-asks the model when validation fails, at the cost of one request per retry.create_iterablereturns a list of objects from one answer, for example every cat in a paragraph.- Instructor also wraps the Anthropic client (
instructor.from_anthropic), which can point at Shannon withbase_url="https://api.shannon-ai.com"; we tested the OpenAI route.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
InstructorRetryException | The answer did not validate after the retries. | Loosen the model's field types or raise max_retries. |
404 Not Found | base_url lacks /v1. | Use https://api.shannon-ai.com/v1. |
401 Unauthorized | The key is missing, mistyped or rotated. | Copy the key again from Keys & usage; it starts with sk-. |
context_length_exceeded / "prompt is too long" | The conversation is longer than the model's window. | Start a new chat, let the tool compact it, or pick a model with a larger window. |
insufficient_quota | Your balance cannot pay for the request. | Top up or change plan; the request is not retried by itself. |
Questions
Does Instructor work with Shannon?
Yes: wrap OpenAI(base_url="https://api.shannon-ai.com/v1") with instructor.from_openai.
Does streaming work?
Yes; create_partial yields the object as it fills in, which we tested.