Async Python client for Grok mobile gRPC API
Project description
Grok3API
An asynchronous library for interacting with Grok via the mobile gRPC channel: sending messages, streaming responses, parsing protobuf chunks, and retrieving structured API data.
➡ Ru README
Features
- asynchronous client
- streaming responses via
new_ask_stream() - regular requests via
new_ask() - protobuf/gRPC framing
- typed Pydantic models
- streaming chunk parsing
- REST/gRPC/stream error handling
- support for metadata/tool responses/search results
Installation
pip install git+ssh://git@github.com/boykopovar/Grok3API.git -U
Requirements
- Python 3.8+
- aiohttp
- coincurve
Streaming Example
import asyncio
from grok3api.client import GrokClient
from grok3api.types.request import ChatRequest
from grok3api.types import TokenChunk
async def main():
async with GrokClient() as client:
while True:
print("\nGrok: ", end="")
async for chunk in client.new_ask_stream(
request=ChatRequest(
message=input("\nYou: "),
temporary=False
),
chunks_white_list=(TokenChunk,)
):
print(chunk.token, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())
Standard Request
import asyncio
from grok3api.client import GrokClient
from grok3api.types.request import ChatRequest
async def main():
async with GrokClient() as client:
response = await client.new_ask(
ChatRequest(
message="Hello",
temporary=False
)
)
print(response.text)
print(response.model_response)
if __name__ == "__main__":
asyncio.run(main())
Continue started conversation
import asyncio
from grok3api.client import GrokClient
from grok3api.types.request import ChatRequest, AddResponseRequest
async def main():
async with GrokClient() as client:
first = await client.new_ask(
ChatRequest(
message="Hello",
temporary=False
)
)
second = await client.add_response(
AddResponseRequest(
conversation_id=first.conversation.conversation_id,
message="How are you?"
)
)
print(second.text)
if __name__ == "__main__":
asyncio.run(main())
Pydantic Models
All models fully match the actual protobuf/gRPC API responses.
The library does not include:
- simplified structures
- artificial abstraction layers
- field normalization
- payload field renaming
- hiding original API values
Supported
Response Chunks
TokenChunkModelResponseChunkFinalMetadataChunkSurveyChunkConversationChunkTitleChunk
Response Models
AskResponseModelResponseFinalMetadataConversationSurveyResponseStepToolUsageResultWebSearchResultXPostRagResultCollectionSearchResultItemConnectorSearchResultItemStreamError
Tool Responses
- web search
- X/Twitter search
- RAG results
- connector search
- collection search
- memory updates
- code execution
- image generation
- video generation
- audio generation
Error Handling
from grok3api.types.exceptions import (
GrokApiError,
GrokRestError,
GrokGrpcError,
GrokRateLimitError,
GrokUnderHeavyUsageError,
GrokStreamError,
GrokUnavailableRegionError,
GrokTooManyRequestsError
)
How the Client Works
- the protobuf request is serialized into a binary payload
- the payload is wrapped into a gRPC frame
- the request is sent to the mobile gRPC endpoint
- the client reads the streaming response
- protobuf chunks are decoded into Pydantic models
Disclaimer
This project is not affiliated with xAI and is not an official SDK.
This is an independent implementation of the mobile Grok API obtained through reverse engineering.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grok3api-0.2.1.tar.gz.
File metadata
- Download URL: grok3api-0.2.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
daf231a763fb6676cf0e32aecd20f5dfcfe2f20b25eb453073362b82f60fe2b2
|
|
| MD5 |
2a77d5cf63fc50de2e3fa46b10b5abf9
|
|
| BLAKE2b-256 |
1ddbde519deaf2d30ba867877c3cc1e1cf7be208ce08666fac448da4c073ee3f
|
Provenance
The following attestation bundles were made for grok3api-0.2.1.tar.gz:
Publisher:
release.yml on boykopovar/Grok3API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grok3api-0.2.1.tar.gz -
Subject digest:
daf231a763fb6676cf0e32aecd20f5dfcfe2f20b25eb453073362b82f60fe2b2 - Sigstore transparency entry: 1942600208
- Sigstore integration time:
-
Permalink:
boykopovar/Grok3API@f28289db9403c501c38f3674e9fce7757594ec07 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f28289db9403c501c38f3674e9fce7757594ec07 -
Trigger Event:
push
-
Statement type:
File details
Details for the file grok3api-0.2.1-py3-none-any.whl.
File metadata
- Download URL: grok3api-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4210a47f4fe1b044d028d767f4041a7afcdcf9d7a2fd1c46e3c02b9b04c42958
|
|
| MD5 |
7190e7accbc4b686dc5261105f0d2b26
|
|
| BLAKE2b-256 |
c36c02b1e4137fa48c8f6bde91a91dc0f6297aabf6f64ba53d03b6056a4a7a73
|
Provenance
The following attestation bundles were made for grok3api-0.2.1-py3-none-any.whl:
Publisher:
release.yml on boykopovar/Grok3API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grok3api-0.2.1-py3-none-any.whl -
Subject digest:
4210a47f4fe1b044d028d767f4041a7afcdcf9d7a2fd1c46e3c02b9b04c42958 - Sigstore transparency entry: 1942600309
- Sigstore integration time:
-
Permalink:
boykopovar/Grok3API@f28289db9403c501c38f3674e9fce7757594ec07 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/boykopovar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f28289db9403c501c38f3674e9fce7757594ec07 -
Trigger Event:
push
-
Statement type: