DEV Community

Sooriya
Sooriya

Posted on AI-assisted

Wrapping the Antigravity (agy) CLI into a Python SDK and OpenAI-Compatible Bridge

If you use Google's Antigravity (agy) CLI, you already know how capable its agentic loop is. I wanted to use that same engine—with streaming tokens, tool execution events, and persistent multi-turn conversations—directly inside Python scripts, bots, and standard OpenAI clients.

So I built and open-sourced antigravity-sdk (v0.1.0, MIT).

How It Works

Instead of reimplementing auth or reverse-engineering endpoints, antigravity-sdk spawns the unmodified agy binary in headless --output-format stream-json mode and parses its NDJSON event stream into typed Python dataclasses:

  • TextDeltaEvent
  • ToolCallEvent
  • ToolResultEvent
  • ResultEvent

Quickstart

git clone https://github.com/Sooriya04/antigravity-sdk.git
cd antigravity-sdk
pip install -e ".[all]"
Enter fullscreen mode Exit fullscreen mode

1. Python SDK (Antigravity / AsyncAntigravity)

from antigravity_sdk import Antigravity

client = Antigravity()
for token in client.stream("Explain quantum entanglement in one sentence."):
    print(token, end="", flush=True)
print()
Enter fullscreen mode Exit fullscreen mode

2. Drop-In OpenAI Bridge (agy-bridge)

Start the FastAPI bridge on port 18790:

agy-bridge --port 18790
Enter fullscreen mode Exit fullscreen mode

Then point any OpenAI client at http://127.0.0.1:18790/v1:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:18790/v1", api_key="not-needed")

stream = client.chat.completions.create(
    model="gemini-4-hydrogen-low",
    messages=[{"role": "user", "content": "Hello Antigravity!"}],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
Enter fullscreen mode Exit fullscreen mode

It also hashes incoming system prompts per session so large system contexts aren't re-sent on every turn unless they actually change.

Repo & Links

Feedback, issues, and PRs are welcome!

Top comments (0)