reka-api


Namereka-api JSON
Version 3.2.0 PyPI version JSON
download
home_pageNone
SummaryReka Python SDK
upload_time2024-09-30 22:42:47
maintainerNone
docs_urlNone
authorReka Team
requires_python<4.0,>=3.8
licenseMIT
keywords reka ai sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Reka Python Library

[![pypi](https://img.shields.io/pypi/v/reka-api)](https://pypi.org/project/reka-api/)
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)

The Reka Python Library provides convenient access to the Reka API from
applications written in Python.

The library includes type definitions for all
request and response fields, and offers both synchronous and asynchronous clients powered by httpx.

## Installation

Add this dependency to your project's build file:

```bash
pip install reka-api
# or
poetry add reka-api
```

## Usage

You need to add your API key for authentication. You can either do that directly when instantiating a
`Reka` client, or by setting the `REKA_API_KEY` environment variable.

Then simply import `Reka` and start making calls to our API.

```python
from reka import ChatMessage
from reka.client import Reka

client = Reka(
    api_key="YOUR_API_KEY",
) # or just client = Reka() if set via env

client.chat.create(
    messages=[
        ChatMessage(
            content="What is the fifth prime number?",
            role="user",
        )
    ],
    model="reka-core-20240501",
)
```

or for multimodality you can do the following:

```python
client.chat.create(
    messages=[
        ChatMessage(
            role="user",
            content=[
                {
                    "type": "video_url":
                    "video_url": "https://fun_video"
                },
                {
                    "type": "text",
                    "text": "What is this video about?"
                },
            ],
        )
    ],
    model="reka-core-20240501",
)
```

Note that the model should work best when you put media content before the text content.

### Typing

To construct payloads you can either use the dedicated types like `ChatMessage` or construct directly from a dictionary like so:

```python
client.chat.create(
    messages=[
        {   
            "role": "user",
            "content": "What is the fifth prime number?"
        }
    ],
    model="reka-core-20240501",
)
```

### V2 SDK

In case you have workloads running the previous version of our SDK, you can import it like this `import reka.v2 as rekav2` and then continue to use it as you are already familiar, e.g.

```python
rekav2.API_KEY = "your-api-key"

response = rekav2.chat("What is the capital of the UK?")
```

## Async Client

The SDK also exports an async client so that you can make non-blocking
calls to our API.

```python
import asyncio
from reka import ChatMessage
from reka.client import AsyncReka

client = AsyncReka(
    api_key="YOUR_API_KEY",
)

async def main() -> None:
    await client.chat.create(
        messages=[
            ChatMessage(
                content="What is the fifth prime number?",
                role="user",
            )
        ],
        model="reka-core-20240501",
    )
asyncio.run(main())
```

## Streaming

The SDK supports streaming endpoints. To take advantage of this feature for chat,
use `chat_stream`.

```Python
from reka import ChatMessage
from reka.client import Reka

client = Reka(
    api_key="YOUR_API_KEY",
)

stream = client.chat.create_stream(
    messages=[
        ChatMessage(
            content="Tell me a short story",
            role="user",
        )
    ],
    model="reka-core-20240501",
)

for message in stream:
    print(message.responses[0].chunk.content, end='\n---\n')
```

## Exception Handling

All errors thrown by the SDK will be subclasses of [`ApiError`](./src/schematic/core/api_error.py).

```python
import reka

try:
    client.chat.create(...)
except reka.core.ApiError as e: # Handle all errors
  print(e.status_code)
  print(e.body)
```

## Advanced

### Timeouts

By default, requests time out after 60 seconds. You can configure this with a
timeout option at the client or request level.

```python
from reka.client import Reka

client = Reka(
    ...,
    # All timeouts are 20 seconds
    timeout=20.0,
)

# Override timeout for a specific method
client.chat.create(..., {
    timeout_in_seconds=20.0
})
```

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be
retried as long as the request is deemed retriable and the number of retry attempts has not grown larger
than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)

Use the `max_retries` request option to configure this behavior.

```python
client.chat.create(..., {
     max_retries=1
})
```

### Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases
include support for proxies and transports.

```python
import httpx

from reka.client import Reka

client = Reka(...,
    httpx_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)
```

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "reka-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "reka, ai, sdk",
    "author": "Reka Team",
    "author_email": "contact@reka.ai",
    "download_url": "https://files.pythonhosted.org/packages/e4/74/6a3ffefc23762304df140a2aef86cbbb69006e3fe712e9b27bd492dfd89a/reka_api-3.2.0.tar.gz",
    "platform": null,
    "description": "# Reka Python Library\n\n[![pypi](https://img.shields.io/pypi/v/reka-api)](https://pypi.org/project/reka-api/)\n[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)\n\nThe Reka Python Library provides convenient access to the Reka API from\napplications written in Python.\n\nThe library includes type definitions for all\nrequest and response fields, and offers both synchronous and asynchronous clients powered by httpx.\n\n## Installation\n\nAdd this dependency to your project's build file:\n\n```bash\npip install reka-api\n# or\npoetry add reka-api\n```\n\n## Usage\n\nYou need to add your API key for authentication. You can either do that directly when instantiating a\n`Reka` client, or by setting the `REKA_API_KEY` environment variable.\n\nThen simply import `Reka` and start making calls to our API.\n\n```python\nfrom reka import ChatMessage\nfrom reka.client import Reka\n\nclient = Reka(\n    api_key=\"YOUR_API_KEY\",\n) #\u00a0or just client = Reka() if set via env\n\nclient.chat.create(\n    messages=[\n        ChatMessage(\n            content=\"What is the fifth prime number?\",\n            role=\"user\",\n        )\n    ],\n    model=\"reka-core-20240501\",\n)\n```\n\nor for multimodality you can do the following:\n\n```python\nclient.chat.create(\n    messages=[\n        ChatMessage(\n            role=\"user\",\n            content=[\n                {\n                    \"type\": \"video_url\":\n                    \"video_url\": \"https://fun_video\"\n                },\n                {\n                    \"type\": \"text\",\n                    \"text\": \"What is this video about?\"\n                },\n            ],\n        )\n    ],\n    model=\"reka-core-20240501\",\n)\n```\n\nNote that the model should work best when you put media content before the text content.\n\n### Typing\n\nTo construct payloads you can either use the dedicated types like `ChatMessage` or construct directly from a dictionary like so:\n\n```python\nclient.chat.create(\n    messages=[\n        {   \n            \"role\": \"user\",\n            \"content\": \"What is the fifth prime number?\"\n        }\n    ],\n    model=\"reka-core-20240501\",\n)\n```\n\n### V2 SDK\n\nIn case you have workloads running the previous version of our SDK, you can import it like this `import reka.v2 as rekav2` and then continue to use it as you are already familiar, e.g.\n\n```python\nrekav2.API_KEY = \"your-api-key\"\n\nresponse = rekav2.chat(\"What is the capital of the UK?\")\n```\n\n## Async Client\n\nThe SDK also exports an async client so that you can make non-blocking\ncalls to our API.\n\n```python\nimport asyncio\nfrom reka import ChatMessage\nfrom reka.client import AsyncReka\n\nclient = AsyncReka(\n    api_key=\"YOUR_API_KEY\",\n)\n\nasync def main() -> None:\n    await client.chat.create(\n        messages=[\n            ChatMessage(\n                content=\"What is the fifth prime number?\",\n                role=\"user\",\n            )\n        ],\n        model=\"reka-core-20240501\",\n    )\nasyncio.run(main())\n```\n\n## Streaming\n\nThe SDK supports streaming endpoints. To take advantage of this feature for chat,\nuse `chat_stream`.\n\n```Python\nfrom reka import ChatMessage\nfrom reka.client import Reka\n\nclient = Reka(\n    api_key=\"YOUR_API_KEY\",\n)\n\nstream = client.chat.create_stream(\n    messages=[\n        ChatMessage(\n            content=\"Tell me a short story\",\n            role=\"user\",\n        )\n    ],\n    model=\"reka-core-20240501\",\n)\n\nfor message in stream:\n    print(message.responses[0].chunk.content, end='\\n---\\n')\n```\n\n## Exception Handling\n\nAll errors thrown by the SDK will be subclasses of [`ApiError`](./src/schematic/core/api_error.py).\n\n```python\nimport reka\n\ntry:\n    client.chat.create(...)\nexcept reka.core.ApiError as e: # Handle all errors\n  print(e.status_code)\n  print(e.body)\n```\n\n## Advanced\n\n### Timeouts\n\nBy default, requests time out after 60 seconds. You can configure this with a\ntimeout option at the client or request level.\n\n```python\nfrom reka.client import Reka\n\nclient = Reka(\n    ...,\n    # All timeouts are 20 seconds\n    timeout=20.0,\n)\n\n# Override timeout for a specific method\nclient.chat.create(..., {\n    timeout_in_seconds=20.0\n})\n```\n\n### Retries\n\nThe SDK is instrumented with automatic retries with exponential backoff. A request will be\nretried as long as the request is deemed retriable and the number of retry attempts has not grown larger\nthan the configured retry limit (default: 2).\n\nA request is deemed retriable when any of the following HTTP status codes is returned:\n\n- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)\n- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)\n- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)\n\nUse the `max_retries` request option to configure this behavior.\n\n```python\nclient.chat.create(..., {\n     max_retries=1\n})\n```\n\n### Custom HTTP client\n\nYou can override the httpx client to customize it for your use-case. Some common use-cases\ninclude support for proxies and transports.\n\n```python\nimport httpx\n\nfrom reka.client import Reka\n\nclient = Reka(...,\n    httpx_client=httpx.Client(\n        proxies=\"http://my.test.proxy.example.com\",\n        transport=httpx.HTTPTransport(local_address=\"0.0.0.0\"),\n    ),\n)\n```\n\n## Contributing\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically.\nAdditions made directly to this library would have to be moved over to our generation code,\notherwise they would be overwritten upon the next generated release. Feel free to open a PR as\na proof of concept, but know that we will not be able to merge it as-is. We suggest opening\nan issue first to discuss with us!\n\nOn the other hand, contributions to the README are always very welcome!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Reka Python SDK",
    "version": "3.2.0",
    "project_urls": null,
    "split_keywords": [
        "reka",
        " ai",
        " sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4e7d4b4724b9b2a2b710d0823bbded93e8480ce5b790291d47c72218666860a",
                "md5": "a42e8af811999f738c6b103c94d3eab1",
                "sha256": "e4ded9df9690f0753d97bd99959aa079bac57272b9d2e1f46ec1415d39984d3f"
            },
            "downloads": -1,
            "filename": "reka_api-3.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a42e8af811999f738c6b103c94d3eab1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 45515,
            "upload_time": "2024-09-30T22:42:46",
            "upload_time_iso_8601": "2024-09-30T22:42:46.507493Z",
            "url": "https://files.pythonhosted.org/packages/f4/e7/d4b4724b9b2a2b710d0823bbded93e8480ce5b790291d47c72218666860a/reka_api-3.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e4746a3ffefc23762304df140a2aef86cbbb69006e3fe712e9b27bd492dfd89a",
                "md5": "091130614006065050532b5c2186f0b7",
                "sha256": "94ee46ad841a64741bef86ff4f71af97d9283020e20152e722891d3cb593d0e9"
            },
            "downloads": -1,
            "filename": "reka_api-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "091130614006065050532b5c2186f0b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 27231,
            "upload_time": "2024-09-30T22:42:47",
            "upload_time_iso_8601": "2024-09-30T22:42:47.613442Z",
            "url": "https://files.pythonhosted.org/packages/e4/74/6a3ffefc23762304df140a2aef86cbbb69006e3fe712e9b27bd492dfd89a/reka_api-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-30 22:42:47",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "reka-api"
}
        
Elapsed time: 1.62776s