This page gives an introduction to using our Chat API, which supports conversations that include images, short videos, and audio.
First, obtain an API key by setting up an account in the Reka Platform.
For Python, install the OpenAI Python SDK with pip install openai — our API is fully OpenAI-compatible.
You can then use your API key to query the models:
This will print a response like:
The fifth prime number is 11. Here’s a quick breakdown of the first five prime numbers in order: 2, 3, 5, 7, 11.
A simple single turn request can be made as follows:
This will return a response like:
See Available Models for details on valid model names.
You can request a response to a multiple turn conversation by adding more messages in the history. For example:
This will return a response like:
We support guiding the assistant output (e.g. prompting it to output a structured JSON response), by allowing the developer to specify how the assistant response should start. This is done by adding a partial assistant response as the last message:
This will output:
The parameters of the Chat API are fully documented in the API reference, but some particularly useful parameters are listed below:
finish_reason in the response is "length".The Chat API supports streaming by setting stream=True in the Python SDK,
or by setting stream to true in the HTTP API.
The OpenAI Python SDK exports an async client so that you can make non-blocking calls to our API. This can be useful to make batch requests. The following code illustrates how to batch calls to the API, by creating a list of async tasks, and gathering them with asyncio.gather. The Semaphore limits the number of concurrent requests to the API.