Skip to main content

Reka Python Library

pypi fern shield

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:

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.

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:

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:

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.

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.

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.

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.

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.

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 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

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.

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!

Metadata

Release files for reka-api 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reka-api 3.2.0
File Size Uploaded
reka_api-3.2.0.tar.gz 27.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for reka-api 3.2.0
File Interpreter ABI Platform
reka_api-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.7 kB

Release files / reka_api-3.2.0.tar.gz

Download URL reka_api-3.2.0.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
94ee46ad841a64741bef86ff4f71af97d9283020e20152e722891d3cb593d0e9
BLAKE2b-256 checksum
How to use checksums
e4746a3ffefc23762304df140a2aef86cbbb69006e3fe712e9b27bd492dfd89a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1073-azure

Release files / reka_api-3.2.0-py3-none-any.whl

Download URL reka_api-3.2.0-py3-none-any.whl
Size 45.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4ded9df9690f0753d97bd99959aa079bac57272b9d2e1f46ec1415d39984d3f
BLAKE2b-256 checksum
How to use checksums
f4e7d4b4724b9b2a2b710d0823bbded93e8480ce5b790291d47c72218666860a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1073-azure

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files

3.1.1

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

2.0.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page