The problem
A model without a search tool cannot know what people are posting now. Even when it recognizes an account or topic, it can confuse remembered information with a current conversation. Opening X with a basic page fetch does not provide a dependable search workflow.
How NativePort helps
Through NativePort, Grok can search X while answering your question. Your agent can use the resulting answer and cited posts as research material. This is a question-driven search, not an export of every matching post.
Technical implementation
Use Python 3 with requests installed (python -m pip install requests). Set NATIVEPORT_API_KEY in your environment to your NativePort key. Run the snippets on your server, where your key stays private.
Choose an available native model ID from GET /grok/v1/models that supports X search and set it as GROK_MODEL. The tool runs on the native Grok Responses route.
import os
import requests
BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}
response = requests.post(BASE + "/grok/v1/responses", headers=HEADERS,
json={"model": os.environ["GROK_MODEL"],
"input": "Find recent posts on X about accessible public transport. Cite the source posts.",
"tools": [{"type": "x_search"}],
"store": False}, timeout=180)
response.raise_for_status()
result = response.json()
for item in result.get("output", []):
for part in item.get("content", []):
if part.get("type") == "output_text":
print(part["text"])
print(part.get("annotations", []))Keep citation annotations with the answer. Tool use has its own cost in addition to model processing. See X search options.
Tool costs
| Tool used in the example | Price per call |
|---|---|
| Grok — X search | Varies by model, tokens, and X search usage |
Prices in USD. Usage-based tools have no fixed per-call price. View pricing.
Let your agent build it
You don’t need to write this code yourself. Copy this page’s link and paste it into your agent. Ask it to follow the guide and implement the feature for you.