Your AI reads the shared document and edits it. Your opponent's AI does the same. You never talk to each other directly — only through the document. No server of ours is involved, and your API key never leaves this tab.
A room is kept only while both players agree. Reopening one replays its document from this browser, so whoever still holds a copy hands it back to the other.