xai-grok


Namexai-grok JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryA community-maintained SDK (Standard Developer Kit) for XAI Grok models
upload_time2025-02-12 01:54:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License Copyright (c) [2024] [Vikram Guhan Subbiah] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords xai xai xai grok grok sdk sdk xdk xdk ai llm
VCS
bugtrack_url
requirements annotated-types certifi charset-normalizer idna pydantic pydantic_core requests typing_extensions urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <img width="650" alt="Screenshot 2025-01-05 at 4 45 45 PM" src="https://github.com/user-attachments/assets/7a8e38eb-9908-409b-9270-cbb2a97b8be5" />
</div>

# Grok Community XDK
A community-maintained SDK (Standard Developer Kit) for XAI Grok models
supporting usage with the Python Programming Language. This library provides
convenient access to the xAI REST API from Python 3.11+ applications, with
type definitions for all request parameters and response fields.

## Installation

```bash
pip install xai-grok
```

## Requirements

- Python 3.11 or higher
- pydantic
- requests

## Usage

```python
from xai_grok import Grok

client = Grok(
    api_key="your-api-key-here"
)

# Example: Create a chat completion
response = client.chat_completions(
    ChatRequest(
        messages=[
            {"role": "user", "content": "Tell me about AI"}
        ],
        model="model-name-here"
    )
)
print(response.choices[0].message.content)
```

## Available Endpoints

### API Key Operations
- `api_key()` - Retrieve information about the current API key

### Chat and Completion Operations
- `chat_completions(request: ChatRequest)` - Create chat completions
  - Input: ChatRequest object containing messages and model settings
  - Throws: InvalidRequestError, IncompleteRequestError

- `complete(request: CompleteRequest)` - Generate completions
  - Input: CompleteRequest object with prompt and settings
  - Throws: InvalidRequestError, IncompleteRequestError

- `completions(request: SampleRequest)` - Alternative completion endpoint
  - Input: SampleRequest object
  - Throws: InvalidRequestError, IncompleteRequestError

### Embedding Operations
- `embedding_model(model_id: str)` - Get details of a specific embedding model
  - Input: Model ID string
  - Throws: ModelNotFoundError

- `embedding_models()` - List all available embedding models

- `embeddings(request: EmbeddingRequest)` - Generate embeddings
  - Input: EmbeddingRequest object
  - Throws: InvalidRequestError, IncompleteRequestError

### Language Model Operations
- `language_model(model_id: str)` - Get details of a specific language model
  - Input: Model ID string
  - Throws: ModelNotFoundError

- `language_models()` - List all available language models

### Message Operations
- `messages(request: MessageRequest)` - Send messages
  - Input: MessageRequest object
  - Throws: InvalidRequestError, IncompleteRequestError

### Model Management
- `models()` - List all available models

- `model(model_id: str)` - Get details of a specific model
  - Input: Model ID string
  - Throws: ModelNotFoundError

### Text Operations
- `tokenize_text(request: TokenizeTextRequest)` - Tokenize input text
  - Input: TokenizeTextRequest object
  - Throws: InvalidRequestError

## Request and Response Types

All request and response types are Pydantic models, providing type safety and
validation. Refer to the schemas module for detailed type definitions.

## Base URL

The API uses `https://api.x.ai` as the base URL for all endpoints.

## Authentication

The API requires an authorized API key. Authentication-related errors are
handled by specific error types:

- `NoAPIKeyProvidedError`: Raised when no API key is provided in the Authorization header
- `InvalidAPIKeyProvidedError`: Raised when an incorrect API key is provided

To avoid these errors:
1. Obtain a valid API key from console.x.ai
2. Include it in the client initialization:
```python
client = Grok(api_key="your-api-key-here")
```

## Note on Responses

All responses are parsed into their corresponding Pydantic models, providing
type-safe access to response data. If the API response cannot be parsed into
the expected type, a `FailedToParseResponseError` will be raised.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xai-grok",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "xai, xAI, XAI, grok, Grok, sdk, SDK, xdk, XDK, ai, llm",
    "author": null,
    "author_email": "Vikram Subbiah <45928972+tiovikram@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/63/f9/7298acdc2fd3bcc93338b52f256ac56c7b34d3447fe9fe31e071a62850c5/xai_grok-0.0.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <img width=\"650\" alt=\"Screenshot 2025-01-05 at 4 45 45\u202fPM\" src=\"https://github.com/user-attachments/assets/7a8e38eb-9908-409b-9270-cbb2a97b8be5\" />\n</div>\n\n# Grok Community XDK\nA community-maintained SDK (Standard Developer Kit) for XAI Grok models\nsupporting usage with the Python Programming Language. This library provides\nconvenient access to the xAI REST API from Python 3.11+ applications, with\ntype definitions for all request parameters and response fields.\n\n## Installation\n\n```bash\npip install xai-grok\n```\n\n## Requirements\n\n- Python 3.11 or higher\n- pydantic\n- requests\n\n## Usage\n\n```python\nfrom xai_grok import Grok\n\nclient = Grok(\n    api_key=\"your-api-key-here\"\n)\n\n# Example: Create a chat completion\nresponse = client.chat_completions(\n    ChatRequest(\n        messages=[\n            {\"role\": \"user\", \"content\": \"Tell me about AI\"}\n        ],\n        model=\"model-name-here\"\n    )\n)\nprint(response.choices[0].message.content)\n```\n\n## Available Endpoints\n\n### API Key Operations\n- `api_key()` - Retrieve information about the current API key\n\n### Chat and Completion Operations\n- `chat_completions(request: ChatRequest)` - Create chat completions\n  - Input: ChatRequest object containing messages and model settings\n  - Throws: InvalidRequestError, IncompleteRequestError\n\n- `complete(request: CompleteRequest)` - Generate completions\n  - Input: CompleteRequest object with prompt and settings\n  - Throws: InvalidRequestError, IncompleteRequestError\n\n- `completions(request: SampleRequest)` - Alternative completion endpoint\n  - Input: SampleRequest object\n  - Throws: InvalidRequestError, IncompleteRequestError\n\n### Embedding Operations\n- `embedding_model(model_id: str)` - Get details of a specific embedding model\n  - Input: Model ID string\n  - Throws: ModelNotFoundError\n\n- `embedding_models()` - List all available embedding models\n\n- `embeddings(request: EmbeddingRequest)` - Generate embeddings\n  - Input: EmbeddingRequest object\n  - Throws: InvalidRequestError, IncompleteRequestError\n\n### Language Model Operations\n- `language_model(model_id: str)` - Get details of a specific language model\n  - Input: Model ID string\n  - Throws: ModelNotFoundError\n\n- `language_models()` - List all available language models\n\n### Message Operations\n- `messages(request: MessageRequest)` - Send messages\n  - Input: MessageRequest object\n  - Throws: InvalidRequestError, IncompleteRequestError\n\n### Model Management\n- `models()` - List all available models\n\n- `model(model_id: str)` - Get details of a specific model\n  - Input: Model ID string\n  - Throws: ModelNotFoundError\n\n### Text Operations\n- `tokenize_text(request: TokenizeTextRequest)` - Tokenize input text\n  - Input: TokenizeTextRequest object\n  - Throws: InvalidRequestError\n\n## Request and Response Types\n\nAll request and response types are Pydantic models, providing type safety and\nvalidation. Refer to the schemas module for detailed type definitions.\n\n## Base URL\n\nThe API uses `https://api.x.ai` as the base URL for all endpoints.\n\n## Authentication\n\nThe API requires an authorized API key. Authentication-related errors are\nhandled by specific error types:\n\n- `NoAPIKeyProvidedError`: Raised when no API key is provided in the Authorization header\n- `InvalidAPIKeyProvidedError`: Raised when an incorrect API key is provided\n\nTo avoid these errors:\n1. Obtain a valid API key from console.x.ai\n2. Include it in the client initialization:\n```python\nclient = Grok(api_key=\"your-api-key-here\")\n```\n\n## Note on Responses\n\nAll responses are parsed into their corresponding Pydantic models, providing\ntype-safe access to response data. If the API response cannot be parsed into\nthe expected type, a `FailedToParseResponseError` will be raised.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) [2024] [Vikram Guhan Subbiah]\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "A community-maintained SDK (Standard Developer Kit) for XAI Grok models",
    "version": "0.0.1",
    "project_urls": {
        "Documentation": "https://github.com/tiovikram/grok-community-xdk/blob/master/README.md",
        "Homepage": "https://github.com/tiovikram/grok-community-xdk",
        "Issues": "https://github.com/tiovikram/grok-community-xdk/issues",
        "Repository": "https://github.com/tiovikram/grok-community-xdk"
    },
    "split_keywords": [
        "xai",
        " xai",
        " xai",
        " grok",
        " grok",
        " sdk",
        " sdk",
        " xdk",
        " xdk",
        " ai",
        " llm"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b5ca24af581d53a1764d5a06e6db1e85f7533f0dee65490913f052000fd29a2f",
                "md5": "db786862f50e0f65a1e24cbe0f0afe97",
                "sha256": "78eaacdc959bd6b9bb6403f90d70654c97f0f78b7f5fbb2d44c176f415aedfb8"
            },
            "downloads": -1,
            "filename": "xai_grok-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "db786862f50e0f65a1e24cbe0f0afe97",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 29488,
            "upload_time": "2025-02-12T01:54:46",
            "upload_time_iso_8601": "2025-02-12T01:54:46.757507Z",
            "url": "https://files.pythonhosted.org/packages/b5/ca/24af581d53a1764d5a06e6db1e85f7533f0dee65490913f052000fd29a2f/xai_grok-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "63f97298acdc2fd3bcc93338b52f256ac56c7b34d3447fe9fe31e071a62850c5",
                "md5": "f202fc5bc768fe8b77a2a89829b1b6f7",
                "sha256": "81cf1753abff558b5fbe2e57dcfe66d00479c68ae958bb3a66d1fcaefa8f9794"
            },
            "downloads": -1,
            "filename": "xai_grok-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f202fc5bc768fe8b77a2a89829b1b6f7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 18102,
            "upload_time": "2025-02-12T01:54:48",
            "upload_time_iso_8601": "2025-02-12T01:54:48.904443Z",
            "url": "https://files.pythonhosted.org/packages/63/f9/7298acdc2fd3bcc93338b52f256ac56c7b34d3447fe9fe31e071a62850c5/xai_grok-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-12 01:54:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tiovikram",
    "github_project": "grok-community-xdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "annotated-types",
            "specs": [
                [
                    "==",
                    "0.7.0"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2025.1.31"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.4.1"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.10"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "2.10.6"
                ]
            ]
        },
        {
            "name": "pydantic_core",
            "specs": [
                [
                    "==",
                    "2.27.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.12.2"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.3.0"
                ]
            ]
        }
    ],
    "lcname": "xai-grok"
}
        
Elapsed time: 0.80399s