You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expose native web search and image generation in the SDK (#294)
The TEE gateway recently added an opt-in `web_search` flag and native
Gemini image generation. This surfaces both through the LLM client.
Web search:
- `LLM.chat` and `LLM.completion` gain a `web_search: bool = False` arg that
forwards `web_search` to the gateway when enabled. Supported by OpenAI,
Anthropic, Google, and xAI models; billed per search on top of tokens.
- LangChain adapter forwards `web_search` (constructor + per-call kwarg).
- CLI `chat`/`completion` gain a `--web-search` flag.
Image generation:
- Add `GEMINI_2_5_FLASH_IMAGE` and `GEMINI_3_1_FLASH_IMAGE` ("nano banana")
plus `GEMINI_3_5_FLASH` to the `TEE_LLM` enum.
- Surface generated images on `TextGenerationOutput.images` (non-streaming)
and `StreamChunk.images` (final stream chunk) as `data:` URIs.
- CLI saves generated images to disk (`--image-output-dir`) instead of
dumping base64.
Adds examples (`llm_web_search.py`, `llm_image_generation.py`), README and
docstring updates, and unit tests for payload forwarding and image surfacing.
Co-authored-by: Claude <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,8 @@ OpenGradient enables developers to build AI applications with verifiable executi
46
46
47
47
-**Verifiable LLM Inference**: Drop-in replacement for OpenAI and Anthropic APIs with cryptographic attestation
48
48
-**Multi-Provider Support**: Access models from OpenAI, Anthropic, Google, and xAI through a unified interface
49
+
-**Native Web Search**: Opt-in `web_search` flag enables each provider's built-in web search, billed per search
50
+
-**Image Generation**: Native image-output models ("nano banana") return generated images directly on the response
49
51
-**TEE Execution**: Trusted Execution Environment inference with cryptographic verification
50
52
-**Model Hub Integration**: Registry for model discovery, versioning, and deployment
51
53
-**Consensus-Based Verification**: End-to-end verified AI execution through the OpenGradient network
@@ -168,6 +170,37 @@ async for chunk in stream:
168
170
print(chunk.choices[0].delta.content, end="")
169
171
```
170
172
173
+
### Native Web Search
174
+
175
+
Set `web_search=True` to let the model search the web while answering. Each search is billed per search on top of token usage, at the provider's list price. Supported by OpenAI, Anthropic, Google, and xAI models; other providers ignore the flag.
176
+
```python
177
+
completion =await llm.chat(
178
+
model=og.TEE_LLM.CLAUDE_SONNET_4_6,
179
+
messages=[{"role": "user", "content": "What are today's top tech headlines?"}],
180
+
max_tokens=500,
181
+
web_search=True,
182
+
)
183
+
print(completion.chat_output["content"])
184
+
```
185
+
186
+
### Image Generation
187
+
188
+
Native image-output models ("nano banana") return generated images on the response. The generated images are available in `result.images` as `data:` URIs, while any text caption is in `chat_output["content"]`. Images travel out-of-band and are not part of the signed output hash.
189
+
```python
190
+
import base64
191
+
192
+
result =await llm.chat(
193
+
model=og.TEE_LLM.GEMINI_3_1_FLASH_IMAGE,
194
+
messages=[{"role": "user", "content": "A friendly robot reading under a tree"}],
195
+
max_tokens=1024,
196
+
)
197
+
198
+
for i, image inenumerate(result.images or []):
199
+
payload = image.split(",", 1)[1] # strip the "data:image/png;base64," prefix
200
+
withopen(f"image_{i}.png", "wb") as f:
201
+
f.write(base64.b64decode(payload))
202
+
```
203
+
171
204
### Verifiable LangChain Integration
172
205
173
206
Use OpenGradient as a drop-in LLM provider for LangChain agents with network-verified execution:
@@ -219,6 +252,9 @@ The SDK provides access to models from multiple providers via the `og.TEE_LLM` e
0 commit comments