Instructions to use openai/gpt-oss-20b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai/gpt-oss-20b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai/gpt-oss-20b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openai/gpt-oss-20b") model = AutoModelForCausalLM.from_pretrained("openai/gpt-oss-20b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
- Local Apps Settings
- vLLM
How to use openai/gpt-oss-20b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai/gpt-oss-20b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openai/gpt-oss-20b
- SGLang
How to use openai/gpt-oss-20b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openai/gpt-oss-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openai/gpt-oss-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openai/gpt-oss-20b with Docker Model Runner:
docker model run hf.co/openai/gpt-oss-20b
Fix TypeError when an assistant tool call has content: null
Summary
The chat template raises TypeError on an assistant message that has content: null and tool_calls. That is the exact shape the OpenAI Chat Completions API returns for a turn that only calls tools, so appending an assistant response to the conversation and rendering it back, the normal agent loop crashes.
Reproduction
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("openai/gpt-oss-120b")
tools = [{"type": "function", "function": {
"name": "get_weather", "description": "Get weather.",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}]
messages = [
{"role": "user", "content": "Weather in Zurich?"},
# exactly what the API returns for a tool-only turn
{"role": "assistant", "content": None, "tool_calls": [
{"id": "c1", "type": "function",
"function": {"name": "get_weather", "arguments": {"city": "Zurich"}}}]},
{"role": "tool", "name": "get_weather", "tool_call_id": "c1", "content": "18C"},
]
tok.apply_chat_template(messages, tools=tools, add_generation_prompt=True)
# TypeError: argument of type 'NoneType' is not iterable
Cause
{%- if "content" in message %}
{%- if "<|channel|>analysis<|message|>" in message.content or ... %}
The guard tests whether the key is present. The body then runs a substring match against its value. When content is present and null, the guard passes and "..." in None raises.
The check is a validation guard: it exists to reject <|channel|> tags smuggled in through content. A null content cannot contain a tag, so it should be skipped, not inspected.
The identical pattern appears two lines below for thinking, and fails the same way on thinking: null.
Fix
Test the value rather than the key:
- {%- if "content" in message %}
+ {%- if message.content %}
{%- if "<|channel|>analysis<|message|>" in message.content or "<|channel|>final<|message|>" in message.content %}
- {%- if "thinking" in message %}
+ {%- if message.thinking %}
{%- if "<|channel|>analysis<|message|>" in message.thinking or "<|channel|>final<|message|>" in message.thinking %}
Both are validation guards, so skipping them for empty or null values changes nothing about what gets rendered for any value that previously worked.
Verification
I rendered every snapshot of 49 conversation shapes through the template before and after the change. Every conversation that rendered before still renders, and produces a byte-identical prompt. The only difference is that the shapes which previously raised now render.
Omitting the content key entirely, or passing "", already worked before this patch. Only the spec-compliant null failed, which is why this has been easy to miss locally and hard to avoid in production.
Related, not included
Line 305 has a third instance of the same root cause:
{%- if "thinking" in message %}
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
str + None also raises. I left it out because it is on the loop.last and not add_generation_prompt path that the comment describes as training-only, and because changing it alters behaviour for thinking: "" (currently emits an empty analysis block, would emit nothing). Happy to include it if you would prefer the complete fix.
Found with ChatLint, which renders chat templates against a corpus of conversation shapes and checks that they do not crash, drop content, or rewrite history.