Skip to main content

OpenAI's response format for its open-weight model series gpt-oss

Project description

harmony

OpenAI Harmony

OpenAI's response format for its open-weight model series gpt-oss
Try gpt-oss | Learn more | Model card


The gpt-oss models were trained on the harmony response format for defining conversation structures, generating reasoning output and structuring function calls. If you are not using gpt-oss directly but through an API or a provider like HuggingFace, Ollama, or vLLM, you will not have to be concerned about this as your inference solution will handle the formatting. If you are building your own inference solution, this guide will walk you through the prompt format. The format is designed to mimic the OpenAI Responses API, so if you have used that API before, this format should hopefully feel familiar to you. gpt-oss should not be used without using the harmony format as it will not work correctly.

The format enables the model to output to multiple different channels for chain of thought, and tool calling preambles along with regular responses. It also enables specifying various tool namespaces, and structured outputs along with a clear instruction hierarchy. Check out the guide to learn more about the format itself.

<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: 2025-06-28

Reasoning: high

# Valid channels: analysis, commentary, final. Channel must be included for every message.
Calls to these tools must go to the commentary channel: 'functions'.<|end|>

<|start|>developer<|message|># Instructions

Always respond in riddles

# Tools

## functions

namespace functions {

// Gets the location of the user.
type get_location = () => any;

// Gets the current weather in the provided location.
type get_current_weather = (_: {
// The city and state, e.g. San Francisco, CA
location: string,
format?: "celsius" | "fahrenheit", // default: celsius
}) => any;

} // namespace functions<|end|><|start|>user<|message|>What is the weather like in SF?<|end|><|start|>assistant

We recommend using this library when working with models that use the harmony response format

  • Consistent formatting – shared implementation for rendering and parsing keeps token-sequences loss-free.
  • Blazing fast – heavy lifting happens in Rust.
  • First-class Python support – install with pip, typed stubs included, 100 % test parity with the Rust suite.

Using Harmony

Python

Check out the full documentation

Installation

Install the package from PyPI by running

pip install openai-harmony
# or if you are using uv
uv pip install openai-harmony

Example

from openai_harmony import (
    load_harmony_encoding,
    HarmonyEncodingName,
    Role,
    Message,
    Conversation,
    DeveloperContent,
    SystemContent,
)
enc = load_harmony_encoding(HarmonyEncodingName.HARMONY_GPT_OSS)
convo = Conversation.from_messages([
    Message.from_role_and_content(
        Role.SYSTEM,
        SystemContent.new(),
    ),
    Message.from_role_and_content(
        Role.DEVELOPER,
        DeveloperContent.new().with_instructions("Talk like a pirate!")
    ),
    Message.from_role_and_content(Role.USER, "Arrr, how be you?"),
])
tokens = enc.render_conversation_for_completion(convo, Role.ASSISTANT)
print(tokens)
# Later, after the model responded …
parsed = enc.parse_messages_from_completion_tokens(tokens, role=Role.ASSISTANT)
print(parsed)

Rust

Check out the full documentation

Installation

Add the dependency to your Cargo.toml

[dependencies]
openai-harmony = { git = "https://github.com/openai/harmony" }

Example

use openai_harmony::chat::{Message, Role, Conversation};
use openai_harmony::{HarmonyEncodingName, load_harmony_encoding};

fn main() -> anyhow::Result<()> {
    let enc = load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss)?;
    let convo =
        Conversation::from_messages([Message::from_role_and_content(Role::User, "Hello there!")]);
    let tokens = enc.render_conversation_for_completion(&convo, Role::Assistant, None)?;
    println!("{:?}", tokens);
    Ok(())
}

Contributing

The majority of the rendering and parsing is built in Rust for performance and exposed to Python through thin pyo3 bindings.

┌──────────────────┐      ┌───────────────────────────┐
│  Python code     │      │  Rust core (this repo)    │
│  (dataclasses,   │────► │  • chat / encoding logic  │
│   convenience)   │      │  • tokeniser (tiktoken)   │
└──────────────────┘  FFI └───────────────────────────┘

Repository layout

.
├── src/                  # Rust crate
│   ├── chat.rs           # High-level data-structures (Role, Message, …)
│   ├── encoding.rs       # Rendering & parsing implementation
│   ├── registry.rs       # Built-in encodings
│   ├── tests.rs          # Canonical Rust test-suite
│   └── py_module.rs      # PyO3 bindings ⇒ compiled as openai_harmony.*.so
│
├── python/openai_harmony/ # Pure-Python wrapper around the binding
│   └── __init__.py       # Dataclasses + helper API mirroring chat.rs
│
├── tests/                # Python test-suite (1-to-1 port of tests.rs)
├── Cargo.toml            # Rust package manifest
├── pyproject.toml        # Python build configuration for maturin
└── README.md             # You are here 🖖

Developing locally

Prerequisites

  • Rust tool-chain (stable) – https://rustup.rs
  • Python ≥ 3.8 + virtualenv/venv
  • maturin – build tool for PyO3 projects

1. Clone & bootstrap

git clone https://github.com/openai/harmony.git
cd harmony
# Create & activate a virtualenv
python -m venv .venv
source .venv/bin/activate
# Install maturin and test dependencies
pip install maturin pytest mypy ruff  # tailor to your workflow
# Compile the Rust crate *and* install the Python package in editable mode
maturin develop --release

maturin develop builds harmony with Cargo, produces a native extension (openai_harmony.<abi>.so) and places it in your virtualenv next to the pure- Python wrapper – similar to pip install -e . for pure Python projects.

2. Running the test-suites

Rust:

cargo test          # runs src/tests.rs

Python:

pytest              # executes tests/ (mirrors the Rust suite)

Run both in one go to ensure parity:

pytest && cargo test

3. Type-checking & formatting (optional)

mypy harmony        # static type analysis
ruff check .        # linting
cargo fmt --all     # Rust formatter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiles_harmony-0.0.8rc4.tar.gz (281.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tiles_harmony-0.0.8rc4-cp38-abi3-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8+Windows x86-64

tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_i686.whl (3.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_armv7l.whl (3.0 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

tiles_harmony-0.0.8rc4-cp38-abi3-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file tiles_harmony-0.0.8rc4.tar.gz.

File metadata

  • Download URL: tiles_harmony-0.0.8rc4.tar.gz
  • Upload date:
  • Size: 281.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tiles_harmony-0.0.8rc4.tar.gz
Algorithm Hash digest
SHA256 c610adbba18883f9bef6cd0ffd50cc38a8d423d2550cc504ef8d963f2572252d
MD5 59da5c9f14ed90e907c8f580af6355df
BLAKE2b-256 d4a7b6397afe75df77442d70a74202f89741bb71e670a426d465631d090a5dd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4.tar.gz:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 620f447660b97fd7a87a413fdb47fabe92947eeffa3b7b23000f899d29b74ee6
MD5 f2641bc9b60c0a885eab8ddd4c263597
BLAKE2b-256 1b35572ea9f1032ec77bc2d191f64bc0865c24d0b73b61886087be9ebf994f23

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-win_amd64.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bb7ad633275b709229d6b516e0c18bb81d4f04e9b09a56a805900ec9bd94ed73
MD5 b1fc09994c52f0c42e635cda04bc5498
BLAKE2b-256 f1061bc6c5c6a8f9905e4a1d2e44b39ff0c95fbf244fd3e862cfd91c50517d83

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f75d8f03d784407484ed2e1d00efe403cc3f8faec714ce65b73f4ee6d4a612c1
MD5 d7a5e162fef46daff22ea17c9624822f
BLAKE2b-256 402f5696e93369b76ee682fc9e890b258c0db9ec45a889b97ab084ed8e0567f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_i686.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 2b68a7faa3cbe8d18f80e10f618fda53e7e634183ba681b1c6a511d9c502cd77
MD5 1eb3b4992e5def1a45a4ebc1fee5f943
BLAKE2b-256 12e63ebe416bd20eab423140bf3a852ace45e3e1ce75dd49f2f2dd5d56655a83

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_armv7l.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d619bcab1ab24f0f09ff27050f88c7a9006e8f594344d2a0875908883a19d350
MD5 aa505ae739897a7f3775fdd6f4a8b952
BLAKE2b-256 0df086b58e8b6ff8ea818f5587116fa2d05b173c8ca74902acbd1999c98a4b3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57053d264f9970696b7dfe797a827159282dcca3123784883e596653e714736e
MD5 6134e4a47533ebf8f4cdd31429f00c07
BLAKE2b-256 f32ac82479dece72852dd10ba07010256042fa345adfc617718087aa40d2ad38

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2d2992b85a01d38ffc8c7b46d2be6590b1c4f18c356459c34f19bef96e2402f6
MD5 181fdefa7fe5128a3bd98aa8a1dc702f
BLAKE2b-256 f88ec2e458fbae7a027509b4e95245ab4b4fc69e6b4d993029a01809c3fa36c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiles_harmony-0.0.8rc4-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tiles_harmony-0.0.8rc4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44d4a5c7d37443a98e4bc082554800aa7f0d7f69d6846806b612527ed3872995
MD5 c8be816fdbdd6aaab790c32e4343effd
BLAKE2b-256 3c2395dba0ed01c85ff7820ee046010b7d7261e3a396b7b03a82e342b7e46323

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiles_harmony-0.0.8rc4-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: CI.yml on tilesprivacy/tiles-harmony

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page