# OpenAI Responses

> Encode and decode the item-based OpenAI Responses API dialect.

- Path: `Guides > Inference > API Formats > OpenAI Responses`
- Human: https://looprig.com/docs/guides/inference/api-formats/openai-responses
- Machine index: https://looprig.com/llms.txt

`codec/openairesponses` targets `POST /v1/responses`, which is an items API,
not a `messages` array. It implements both client and server codec contracts.

## Items

System text becomes top-level `instructions`. User turns become `message`
items with `input_text`, `input_image`, and `input_file` parts. Assistant tool calls become
`function_call` items; tool results become `function_call_output`. Consecutive
assistant text blocks are grouped into one message item. `store` is always
explicitly `false`, and the neutral `Stop` sampling field is omitted because
this API does not model it.

```go
body, err := openairesponses.EncodeRequest(req, false)
if err != nil {
	return err
}
fmt.Println(string(body)) // inspect the typed items in a test, not in logs for secrets.
```

## Usage and replay

Responses reports gross `input_tokens` and a cached subset. The decoder
subtracts `input_tokens_details.cached_tokens` and leaves
`CacheCreationTokens` zero because the DTO has no creation field. Reasoning
items preserve summary text and an opaque `encrypted_content` value in
`ThinkingBlock.ProviderState`; only a state tagged for this dialect is replayed.
Streaming uses typed SSE events such as `response.output_text.delta` and
`response.completed`.

## Source and proof

- [`openairesponses/types.go`](https://github.com/looprig/inference/blob/v0.12.0/codec/openairesponses/types.go)
- [`openairesponses/encode.go`](https://github.com/looprig/inference/blob/v0.12.0/codec/openairesponses/encode.go)
- [`openairesponses/decode.go`](https://github.com/looprig/inference/blob/v0.12.0/codec/openairesponses/decode.go)
- [`openairesponses/stream.go`](https://github.com/looprig/inference/blob/v0.12.0/codec/openairesponses/stream.go)

Run `go test ./codec/openairesponses`.
