# Format Conversion



Acontext normalizes messages to a unified internal schema on store, and converts back to the target provider format on retrieval.

## Conversion Flow [#conversion-flow]

<Mermaid
  chart="flowchart LR
    subgraph Store[&#x22;Store (Normalize)&#x22;]
        direction TB
        OI[&#x22;OpenAI&#x22;] --> N[&#x22;Acontext Internal Format&#x22;]
        AI[&#x22;Anthropic&#x22;] --> N
        GI[&#x22;Gemini&#x22;] --> N
    end

    N --> C{{&#x22;Retrieve (Convert)&#x22;}}

    subgraph Retrieve[&#x22;Output Format&#x22;]
        direction TB
        OO[&#x22;OpenAI&#x22;]
        AO[&#x22;Anthropic&#x22;]
        GO[&#x22;Gemini&#x22;]
        CO[&#x22;Acontext&#x22;]
    end

    C --> OO
    C --> AO
    C --> GO
    C --> CO"
/>

## Part Type Conversion Matrix [#part-type-conversion-matrix]

Each message is composed of typed parts. The table below shows how each internal part type maps to provider-specific structures on retrieval:

| Internal Part Type | OpenAI                                  | Anthropic                                | Gemini                                        |
| ------------------ | --------------------------------------- | ---------------------------------------- | --------------------------------------------- |
| `text`             | `content` string or `text` content part | `text` block                             | `text` part                                   |
| `image`            | `image_url` content part                | `image` block (base64)                   | `InlineData` part                             |
| `tool-call`        | `tool_calls` array                      | `tool_use` block                         | `FunctionCall` part                           |
| `tool-result`      | `tool` role message                     | `tool_result` block                      | `FunctionResponse` part                       |
| `thinking`         | downgraded to `text` content part       | native `thinking` block with `signature` | native `Thought` part with `ThoughtSignature` |
| `audio`            | `input_audio` content part              | —                                        | —                                             |
| `file`             | `file` content part                     | `document` block                         | —                                             |

<Tip>
  Thinking blocks from Anthropic and Gemini are stored identically and are fully cross-compatible. A thinking block stored from Claude can be retrieved in Gemini format as a native `Thought` part, and vice versa.
</Tip>

## Role Mapping [#role-mapping]

| Provider  | Provider Roles                          | Internal Role         |
| --------- | --------------------------------------- | --------------------- |
| OpenAI    | `user`, `assistant`, `tool`, `function` | `user` or `assistant` |
| Anthropic | `user`, `assistant`                     | `user` or `assistant` |
| Gemini    | `user`, `model`                         | `user` or `assistant` |

On retrieval, `assistant` is converted back to `model` for Gemini format.

## Provider-specific Handling [#provider-specific-handling]

<CardGroup cols="2">
  <Card title="Anthropic Flags" icon="a" href="/store/messages/special/anthropic">
    Cache control and thinking blocks
  </Card>

  <Card title="Gemini Handling" icon="g" href="/store/messages/special/gemini">
    Thinking parts and function call ID generation
  </Card>
</CardGroup>
