> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.reka.ai/chat/overview/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.reka.ai/_mcp/server. This page gives an introduction to using our Chat API, which supports [conversations that include images, short videos, and audio](/chat/chat-with-image-video-and-audio). ## Quickstart First, obtain an API key by setting up an account in the [Reka Platform](https://platform.reka.ai). > **Warning** > > Keep your API key secure. Never share it publicly or expose it in client-side code. For Python, install the [OpenAI Python SDK](https://pypi.org/project/openai/) with `pip install openai` — our API is fully OpenAI-compatible. You can then use your API key to query the models: **`OpenAI SDK`** ```python title="OpenAI SDK" from openai import OpenAI client = OpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) response = client.chat.completions.create( model="reka-flash", messages=[ { "content": "What is the fifth prime number?", "role": "user", } ], ) print(response.choices[0].message.content) ``` **`Python`** ```python title="Python" import requests response = requests.post( "https://api.reka.ai/v1/chat/completions", headers={ "X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json", }, json={ "model": "reka-flash", "messages": [ { "role": "user", "content": "What is the fifth prime number?", } ], }, ) data = response.json() print(data["choices"][0]["message"]["content"]) ``` **`JavaScript`** ```javascript title="JavaScript" const response = await fetch('https://api.reka.ai/v1/chat/completions', { method: 'POST', headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'reka-flash', messages: [ { role: 'user', content: 'What is the fifth prime number?' } ], }), }); const data = await response.json(); console.log(data.choices[0].message.content); ``` **`Go`** ```go title="Go" package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" ) func main() { reqBody, _ := json.Marshal(map[string]interface{}{ "model": "reka-flash", "messages": []map[string]interface{}{ {"role": "user", "content": "What is the fifth prime number?"}, }, }) req, _ := http.NewRequest("POST", "https://api.reka.ai/v1/chat/completions", bytes.NewBuffer(reqBody)) req.Header.Set("X-Api-Key", "YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ``` **`Java`** ```java title="Java" import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; HttpClient client = HttpClient.newHttpClient(); String jsonBody = """ { "model": "reka-flash", "messages": [ { "role": "user", "content": "What is the fifth prime number?" } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.reka.ai/v1/chat/completions")) .header("X-Api-Key", "YOUR_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonBody)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` **`REST`** ```shell title="REST" curl -X POST https://api.reka.ai/v1/chat/completions \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "reka-flash", "messages": [ { "role": "user", "content": "What is the fifth prime number?" } ] }' ``` 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. ## Single Turn Prompting A simple single turn request can be made as follows: **`OpenAI SDK`** ```python title="OpenAI SDK" from openai import OpenAI client = OpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) response = client.chat.completions.create( model="reka-flash", messages=[ { "content": "Write a python one-liner to flatten a list of lists.", "role": "user", } ], ) print(response.choices[0].message.content) ``` **`Python`** ```python title="Python" import requests response = requests.post( "https://api.reka.ai/v1/chat/completions", headers={ "X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json", }, json={ "model": "reka-flash", "messages": [ { "role": "user", "content": "Write a python one-liner to flatten a list of lists.", } ], }, ) data = response.json() print(data["choices"][0]["message"]["content"]) ``` **`JavaScript`** ```javascript title="JavaScript" const response = await fetch('https://api.reka.ai/v1/chat/completions', { method: 'POST', headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'reka-flash', messages: [ { role: 'user', content: 'Write a python one-liner to flatten a list of lists.' } ], }), }); const data = await response.json(); console.log(data.choices[0].message.content); ``` **`Go`** ```go title="Go" package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" ) func main() { reqBody, _ := json.Marshal(map[string]interface{}{ "model": "reka-flash", "messages": []map[string]interface{}{ {"role": "user", "content": "Write a python one-liner to flatten a list of lists."}, }, }) req, _ := http.NewRequest("POST", "https://api.reka.ai/v1/chat/completions", bytes.NewBuffer(reqBody)) req.Header.Set("X-Api-Key", "YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ``` **`Java`** ```java title="Java" import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; HttpClient client = HttpClient.newHttpClient(); String jsonBody = """ { "model": "reka-flash", "messages": [ { "role": "user", "content": "Write a python one-liner to flatten a list of lists." } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.reka.ai/v1/chat/completions")) .header("X-Api-Key", "YOUR_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonBody)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` **`REST`** ```shell title="REST" curl -X POST https://api.reka.ai/v1/chat/completions \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "reka-flash", "messages": [ { "role": "user", "content": "Write a python one-liner to flatten a list of lists." } ] }' ``` This will return a response like: ```` Here's a Python one-liner using list comprehension to flatten a list of lists: ```python flattened_list = [item for sublist in nested_list for item in sublist] ``` Replace `nested_list` with your actual list of lists. This one-liner works by iterating over each sublist in the outer list, and then iterating over each item in those sublists, effectively flattening the structure into a single list. ```` See [Available Models](/chat/models) for details on valid model names. ## Multiple Turn Conversations You can request a response to a multiple turn conversation by adding more messages in the history. For example: **`OpenAI SDK`** ```python title="OpenAI SDK" maxLines=22 from openai import OpenAI client = OpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) response = client.chat.completions.create( model="reka-flash", messages=[ { "content": "My name is Matt.", "role": "user", }, { "content": "Hello Matt! How can I help you today?", "role": "assistant", }, { "content": "Can you think of a couple of famous people with the same name as me?", "role": "user", }, ], ) print(response.choices[0].message.content) ``` **`Python`** ```python title="Python" maxLines=22 import requests response = requests.post( "https://api.reka.ai/v1/chat/completions", headers={ "X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json", }, json={ "model": "reka-flash", "messages": [ { "role": "user", "content": "My name is Matt.", }, { "role": "assistant", "content": "Hello Matt! How can I help you today?", }, { "role": "user", "content": "Can you think of a couple of famous people with the same name as me?", }, ], }, ) data = response.json() print(data["choices"][0]["message"]["content"]) ``` **`JavaScript`** ```javascript title="JavaScript" maxLines=22 const response = await fetch('https://api.reka.ai/v1/chat/completions', { method: 'POST', headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'reka-flash', messages: [ { role: 'user', content: 'My name is Matt.' }, { role: 'assistant', content: 'Hello Matt! How can I help you today?' }, { role: 'user', content: 'Can you think of a couple of famous people with the same name as me?' } ], }), }); const data = await response.json(); console.log(data.choices[0].message.content); ``` **`Go`** ```go title="Go" maxLines=22 package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" ) func main() { reqBody, _ := json.Marshal(map[string]interface{}{ "model": "reka-flash", "messages": []map[string]interface{}{ {"role": "user", "content": "My name is Matt."}, {"role": "assistant", "content": "Hello Matt! How can I help you today?"}, {"role": "user", "content": "Can you think of a couple of famous people with the same name as me?"}, }, }) req, _ := http.NewRequest("POST", "https://api.reka.ai/v1/chat/completions", bytes.NewBuffer(reqBody)) req.Header.Set("X-Api-Key", "YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ``` **`Java`** ```java title="Java" maxLines=22 import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; HttpClient client = HttpClient.newHttpClient(); String jsonBody = """ { "model": "reka-flash", "messages": [ { "role": "user", "content": "My name is Matt." }, { "role": "assistant", "content": "Hello Matt! How can I help you today?" }, { "role": "user", "content": "Can you think of a couple of famous people with the same name as me?" } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.reka.ai/v1/chat/completions")) .header("X-Api-Key", "YOUR_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonBody)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` **`REST`** ```shell title="REST" maxLines=22 curl -X POST https://api.reka.ai/v1/chat/completions \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "reka-flash", "messages": [ { "role": "user", "content": "My name is Matt." }, { "role": "assistant", "content": "Hello Matt! How can I help you today?" }, { "role": "user", "content": "Can you think of a couple of famous people with the same name as me?" } ] }' ``` This will return a response like: ```plaintext Certainly, Matt is a popular name, and there are several famous individuals with that name across various fields. Here are a few: 1. **Matt Damon** - An acclaimed actor known for his roles in movies like "Good Will Hunting," the "Bourne" series, and "The Martian." 2. **Matt LeBlanc** - An actor best known for playing Joey Tribbiani on the television series "Friends" and for hosting "Top Gear." 3. **Matt Groening** - The creator of the iconic animated television series "The Simpsons" and "Futurama." 4. **Matt Smith** - An actor who played the Eleventh Doctor in the British television series "Doctor Who" and has also starred in "The Crown." 5. **Matt Bomer** - An actor, producer, and director known for his roles in "White Collar," "Magic Mike," and "The Normal Heart." 6. **Matt Ryan** - An actor known for his role as John Constantine in the television series "Constantine" and for voicing the character in various video games. These are just a few examples of the many famous Matts out there. Each has made significant contributions to their respective fields. ``` ## Assistant Completions 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: **`OpenAI SDK`** ````python title="OpenAI SDK" maxLines=42 from openai import OpenAI client = OpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) prompt = """ Below is a paragraph from wikipedia: The Solar System is the gravitationally bound system of the Sun and the objects that orbit it. The largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury, Venus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune. The terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are mostly made of hydrogen and helium, while the ice giants are mostly made of 'volatile' substances such as water, ammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer Solar System planets respectively. Extract information about the planets from this paragraph as a JSON list of objects with keys 'planetName' and 'composition'. The 'composition' key should contain one or two words, and there should be no other keys. """.strip() json_prefix = """ [ { "planetName": """.strip() response = client.chat.completions.create( model="reka-flash", messages=[ {"role": "user", "content": prompt}, { "role": "assistant", "content": ( "Sure, here is a JSON object conforming to that format:\n\n" f"```json\n{json_prefix}" ), }, ], max_tokens=512, temperature=0.4, stop=["```\n"], ) print(json_prefix + response.choices[0].message.content) ```` **`Python`** ````python title="Python" maxLines=42 import requests prompt = """ Below is a paragraph from wikipedia: The Solar System is the gravitationally bound system of the Sun and the objects that orbit it. The largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury, Venus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune. The terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are mostly made of hydrogen and helium, while the ice giants are mostly made of 'volatile' substances such as water, ammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer Solar System planets respectively. Extract information about the planets from this paragraph as a JSON list of objects with keys 'planetName' and 'composition'. The 'composition' key should contain one or two words, and there should be no other keys. """.strip() json_prefix = """ [ { "planetName": """.strip() response = requests.post( "https://api.reka.ai/v1/chat/completions", headers={ "X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json", }, json={ "model": "reka-flash", "max_tokens": 512, "temperature": 0.4, "stop": ["```\n"], "messages": [ {"role": "user", "content": prompt}, { "role": "assistant", "content": ( "Sure, here is a JSON object conforming to that format:\n\n" f"```json\n{json_prefix}" ), }, ], }, ) data = response.json() print(json_prefix + data["choices"][0]["message"]["content"]) ```` **`JavaScript`** ````javascript title="JavaScript" maxLines=42 const prompt = `Below is a paragraph from wikipedia: The Solar System is the gravitationally bound system of the Sun and the objects that orbit it. The largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury, Venus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune. The terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are mostly made of hydrogen and helium, while the ice giants are mostly made of volatile substances such as water, ammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer Solar System planets respectively. Extract information about the planets from this paragraph as a JSON list of objects with keys 'planetName' and 'composition'. The 'composition' key should contain one or two words, and there should be no other keys.`; const jsonPrefix = '[\n {\n "planetName":'; const response = await fetch('https://api.reka.ai/v1/chat/completions', { method: 'POST', headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'reka-flash', max_tokens: 512, temperature: 0.4, stop: ['```\n'], messages: [ { role: 'user', content: prompt }, { role: 'assistant', content: 'Sure, here is a JSON object conforming to that format:\n\n```json\n' + jsonPrefix, } ], }), }); const data = await response.json(); console.log(jsonPrefix + data.choices[0].message.content); ```` **`Go`** ````go title="Go" maxLines=42 package main import ( "fmt" "io" "net/http" "strings" ) func main() { jsonStr := `{ "model": "reka-flash", "max_tokens": 512, "temperature": 0.4, "stop": ["` + "```\\n" + `"], "messages": [ { "role": "user", "content": "Below is a paragraph from wikipedia:\n\nThe Solar System is the gravitationally bound system of the Sun and the objects that orbit it.\nThe largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury,\nVenus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune.\nThe terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are\nmostly made of hydrogen and helium, while the ice giants are mostly made of volatile substances such as water,\nammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer\nSolar System planets respectively.\n\nExtract information about the planets from this paragraph as a JSON list of objects with keys \"planetName\" and\n\"composition\". The \"composition\" key should contain one or two words, and there should be no other keys." }, { "role": "assistant", "content": "Sure, here is a JSON object conforming to that format:\n\n` + "```json\\n[\\n {\\n \\\"planetName\\\":" + `" } ] }` req, _ := http.NewRequest("POST", "https://api.reka.ai/v1/chat/completions", strings.NewReader(jsonStr)) req.Header.Set("X-Api-Key", "YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ```` **`Java`** ````java title="Java" maxLines=42 import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; HttpClient client = HttpClient.newHttpClient(); String jsonBody = """ { "model": "reka-flash", "max_tokens": 512, "temperature": 0.4, "stop": ["```\\n"], "messages": [ { "role": "user", "content": "Below is a paragraph from wikipedia:\\n\\nThe Solar System is the gravitationally bound system of the Sun and the objects that orbit it.\\nThe largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury,\\nVenus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune.\\nThe terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are\\nmostly made of hydrogen and helium, while the ice giants are mostly made of volatile substances such as water,\\nammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer\\nSolar System planets respectively.\\n\\nExtract information about the planets from this paragraph as a JSON list of objects with keys \\"planetName\\" and\\n\\"composition\\". The \\"composition\\" key should contain one or two words, and there should be no other keys." }, { "role": "assistant", "content": "Sure, here is a JSON object conforming to that format:\\n\\n```json\\n[\\n {\\n \\"planetName\\":" } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.reka.ai/v1/chat/completions")) .header("X-Api-Key", "YOUR_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonBody)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ```` **`REST`** ````shell title="REST" maxLines=42 curl -X POST https://api.reka.ai/v1/chat/completions \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "reka-flash", "max_tokens": 512, "temperature": 0.4, "stop": ["```\n"], "messages": [ { "role": "user", "content": "Below is a paragraph from wikipedia:\n\nThe Solar System is the gravitationally bound system of the Sun and the objects that orbit it.\nThe largest of such objects are the eight planets, in order from the Sun: four terrestrial planets named Mercury,\nVenus, Earth and Mars, two gas giants named Jupiter and Saturn, and two ice giants named Uranus and Neptune.\nThe terrestrial planets have a definite surface and are mostly made of rock and metal. The gas giants are\nmostly made of hydrogen and helium, while the ice giants are mostly made of volatile substances such as water,\nammonia, and methane. In some texts, these terrestrial and giant planets are called the inner Solar System and outer\nSolar System planets respectively.\n\nExtract information about the planets from this paragraph as a JSON list of objects with keys \"planetName\" and\n\"composition\". The \"composition\" key should contain one or two words, and there should be no other keys." }, { "role": "assistant", "content": "Sure, here is a JSON object conforming to that format:\n\n```json\n[\n {\n \"planetName\":" } ] }' ```` This will output: ```json maxLines=34 [ { "planetName": "Mercury", "composition": "rock, metal" }, { "planetName": "Venus", "composition": "rock, metal" }, { "planetName": "Earth", "composition": "rock, metal" }, { "planetName": "Mars", "composition": "rock, metal" }, { "planetName": "Jupiter", "composition": "hydrogen, helium" }, { "planetName": "Saturn", "composition": "hydrogen, helium" }, { "planetName": "Uranus", "composition": "water, ammonia, methane" }, { "planetName": "Neptune", "composition": "water, ammonia, methane" } ] ``` ## Useful Parameters The parameters of the Chat API are [fully documented in the API reference](/chat/api-reference/), but some particularly useful parameters are listed below: * **temperature**: Typically between 0 and 1. Values close to 0 will result in less varied generations, and higher values will result in more variation and creativity. * **max\_tokens**: The maximum number of tokens that should be returned. Increase this if generations are being truncated, i.e. the [`finish_reason`](/chat/api-reference/create#response.body.choices.finish_reason) in the response is `"length"`. * **stop**: A list of strings that should stop the generation. This can be used to stop after generating a code block, when reaching a certain number in a list etc. ## Streaming The Chat API supports streaming by setting `stream=True` in the Python SDK, or by setting [`stream`](/chat/api-reference/create#request.body.stream) to `true` in the HTTP API. **`OpenAI SDK`** ```python title="OpenAI SDK" from openai import OpenAI client = OpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) response = client.chat.completions.create( model="reka-flash", stream=True, max_tokens=2048, messages=[ { "content": "Write a detailed template NDA contract between two parties.", "role": "user", } ], ) for chunk in response: content = chunk.choices[0].delta.content if content: print(content, end="") ``` **`Python`** ```python title="Python" import json import requests response = requests.post( "https://api.reka.ai/v1/chat/completions", headers={ "X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json", }, json={ "model": "reka-flash", "stream": True, "max_tokens": 2048, "messages": [ { "role": "user", "content": "Write a detailed template NDA contract between two parties.", } ], }, stream=True, ) for line in response.iter_lines(): if line: line = line.decode("utf-8") if line.startswith("data: ") and line != "data: [DONE]": chunk = json.loads(line[6:]) content = chunk["choices"][0]["delta"].get("content", "") if content: print(content, end="") ``` **`JavaScript`** ```javascript title="JavaScript" const response = await fetch('https://api.reka.ai/v1/chat/completions', { method: 'POST', headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'reka-flash', stream: true, max_tokens: 2048, messages: [ { role: 'user', content: 'Write a detailed template NDA contract between two parties.' } ], }), }); const reader = response.body.getReader(); const decoder = new TextDecoder(); while (true) { const { done, value } = await reader.read(); if (done) break; process.stdout.write(decoder.decode(value)); } ``` **`Go`** ```go title="Go" package main import ( "bufio" "bytes" "encoding/json" "fmt" "net/http" ) func main() { reqBody, _ := json.Marshal(map[string]interface{}{ "model": "reka-flash", "stream": true, "max_tokens": 2048, "messages": []map[string]interface{}{ {"role": "user", "content": "Write a detailed template NDA contract between two parties."}, }, }) req, _ := http.NewRequest("POST", "https://api.reka.ai/v1/chat/completions", bytes.NewBuffer(reqBody)) req.Header.Set("X-Api-Key", "YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() scanner := bufio.NewScanner(resp.Body) for scanner.Scan() { fmt.Println(scanner.Text()) } } ``` **`Java`** ```java title="Java" import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.io.BufferedReader; import java.io.InputStreamReader; HttpClient client = HttpClient.newHttpClient(); String jsonBody = """ { "model": "reka-flash", "stream": true, "max_tokens": 2048, "messages": [ { "role": "user", "content": "Write a detailed template NDA contract between two parties." } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.reka.ai/v1/chat/completions")) .header("X-Api-Key", "YOUR_API_KEY") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonBody)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofInputStream()); try (BufferedReader reader = new BufferedReader( new InputStreamReader(response.body()))) { String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } ``` **`REST`** ```shell title="REST" curl -X POST https://api.reka.ai/v1/chat/completions \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ --no-buffer \ -d '{ "model": "reka-flash", "stream": true, "max_tokens": 2048, "messages": [ { "role": "user", "content": "Write a detailed template NDA contract between two parties." } ] }' ``` ## Async 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. ```python maxLines=35 import asyncio from openai import AsyncOpenAI client = AsyncOpenAI( base_url="https://api.reka.ai/v1", api_key="YOUR_API_KEY", ) max_concurrent_requests = 2 semaphore = asyncio.Semaphore(max_concurrent_requests) async def respond(prompt: str) -> str: async with semaphore: response = await client.chat.completions.create( model="reka-flash", messages=[ { "content": prompt, "role": "user", } ], ) return response.choices[0].message async def main(): prompts = [ "What is your name?", "What is the fifth prime number?", "Write a python one-liner to flatten a list of lists.", ] responses = await asyncio.gather(*[respond(prompt) for prompt in prompts]) return responses asyncio.run(main()) ``` > Documentation for Reka AI APIs.