Chat Completions
Chat Completions is the endpoint everything else hangs off: send a list of messages, get the model’s reply, in the OpenAI request and response shape.
POST/chat/completions
| Parameter | Type | Required | Description |
| model | string | Yes | ID of the model to use (e.g., “meta-llama/Llama-3.3-70B-Instruct”, “deepseek-ai/DeepSeek-R1-0528”) |
| messages | array | Yes | Array of message objects with role and content |
| temperature | number | No | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic |
| max_tokens | integer | No | Maximum tokens to generate (default varies by model) |
| tools | array | No | Live-data oracles the model may call, e.g. [{ “type”: “weather” }] — see Live data (oracles). Standard function tools are accepted too. Each oracle call is billed per successful lookup on top of the tokens. |
Example Request
Section titled “Example Request”from openai import OpenAI
# Set your API key and base URLclient = OpenAI( base_url = "https://api.oraicle.me/v1", # For production, you should not place your key # in the code but in the environment variables api_key = "<your_api_key>",)
# Make a simple chat completion requestresponse = client.chat.completions.create( model="deepseek-ai/DeepSeek-R1-0528", messages=[ {"role": "system", "content": "You are a smarter assistant."}, { "role": "user", "content": "In two sentences, what is an API key and why should I keep it secret?" } ])
print(response.choices[0].message.content)import { OpenAI } from "openai";
// Set up the client with your API key and base URLconst openai = new OpenAI({ apiKey: "<your_api_key>", baseURL: "https://api.oraicle.me/v1"});
async function callAPI() { const completion = await openai.chat.completions.create({ model: "deepseek-ai/DeepSeek-R1-0528", messages: [ { role: "system", content: "You are a smarter assistant." }, { role: "user", content: "In two sentences, what is an API key and why should I keep it secret?" } ], });
console.log(completion.choices[0].message.content);}
callAPI();curl https://api.oraicle.me/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <your_api_key>" \ -d '{ "model": "deepseek-ai/DeepSeek-R1-0528", "messages": [ { "role": "system", "content": "You are a smarter assistant." }, { "role": "user", "content": "In two sentences, what is an API key and why should I keep it secret?" } ] }'import com.theokanning.openai.completion.chat.ChatCompletionRequest;import com.theokanning.openai.completion.chat.ChatMessage;import com.theokanning.openai.completion.chat.ChatMessageRole;import com.theokanning.openai.service.OpenAiService;import retrofit2.Retrofit;
import java.time.Duration;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;
public class OraicleExample { public static void main(String[] args) { String token = "<your_api_key>"; String baseUrl = "https://api.oraicle.me/v1";
// Create a service with custom base URL OpenAiService service = new OpenAiService(token, Duration.ofSeconds(30), baseUrl);
List messages = new ArrayList<>(); messages.add(new ChatMessage(ChatMessageRole.SYSTEM.value(), "You are a smarter assistant.")); messages.add(new ChatMessage(ChatMessageRole.USER.value(), "In two sentences, what is an API key and why should I keep it secret?"));
ChatCompletionRequest completionRequest = ChatCompletionRequest.builder() .model("deepseek-ai/DeepSeek-R1-0528") .messages(messages) .build();
service.createChatCompletion(completionRequest) .getChoices() .forEach(choice -> System.out.println(choice.getMessage().getContent())); }}using System;using System.Collections.Generic;using System.Net.Http;using System.Text;using System.Text.Json;using System.Threading.Tasks;
class Program{ static async Task Main(string[] args) { var apiKey = "<your_api_key>"; var baseUrl = "https://api.oraicle.me/v1";
using var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var requestData = new { model = "deepseek-ai/DeepSeek-R1-0528", messages = new[] { new { role = "system", content = "You are a smarter assistant." }, new { role = "user", content = "In two sentences, what is an API key and why should I keep it secret?" } } };
var content = new StringContent( JsonSerializer.Serialize(requestData), Encoding.UTF8, "application/json");
var response = await client.PostAsync($"{baseUrl}/chat/completions", content); var responseBody = await response.Content.ReadAsStringAsync();
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var result = JsonSerializer.Deserialize(responseBody, options);
Console.WriteLine(result.Choices[0].Message.Content); }}
class CompletionResponse{ public Choice[] Choices { get; set; }}
class Choice{ public Message Message { get; set; }}
class Message{ public string Content { get; set; }}package main
import ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http")
type ChatCompletionRequest struct { Model string `json:"model"` Messages []Message `json:"messages"`}
type Message struct { Role string `json:"role"` Content string `json:"content"`}
type ChatCompletionResponse struct { Choices []Choice `json:"choices"`}
type Choice struct { Message Message `json:"message"`}
func main() { apiKey := "<your_api_key>" baseURL := "https://api.oraicle.me/v1"
// Create request body reqBody := ChatCompletionRequest{ Model: "deepseek-ai/DeepSeek-R1-0528", Messages: []Message{ {Role: "system", Content: "You are a smarter assistant."}, {Role: "user", Content: "In two sentences, what is an API key and why should I keep it secret?"}, }, }
// Marshal the request body to JSON jsonData, err := json.Marshal(reqBody) if err != nil { fmt.Println("Error marshaling JSON:", err) return }
// Create HTTP request req, err := http.NewRequest("POST", baseURL+"/chat/completions", bytes.NewBuffer(jsonData)) if err != nil { fmt.Println("Error creating request:", err) return }
// Set headers req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+apiKey)
// Send the request client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close()
// Read the response body body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response:", err) return }
// Parse the response var result ChatCompletionResponse if err := json.Unmarshal(body, &result); err != nil { fmt.Println("Error parsing response:", err) return }
// Print the assistant's reply fmt.Println(result.Choices[0].Message.Content)}<?php$apiKey = '<your_api_key>';$baseUrl = 'https://api.oraicle.me/v1';
$data = [ 'model' => 'deepseek-ai/DeepSeek-R1-0528', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a smarter assistant.' ], [ 'role' => 'user', 'content' => 'In two sentences, what is an API key and why should I keep it secret?' ] ]];
$headers = [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey];
$ch = curl_init($baseUrl . '/chat/completions');curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);curl_close($ch);
if ($httpStatus === 200) { $responseData = json_decode($response, true); echo $responseData['choices'][0]['message']['content'];} else { echo "Error: " . $httpStatus . "\n" . $response;}?>The Response
Section titled “The Response”{ "id": "chatcmpl-123abc456def", "object": "chat.completion", "created": 1677858242, "model": "deepseek-ai/DeepSeek-R1-0528", "usage": { "prompt_tokens": 31, "completion_tokens": 62, "total_tokens": 93 }, "choices": [ { "message": { "role": "assistant", "content": "An API key is a secret string that identifies your account when your code calls a service, so each request can be authorised and billed to you. Keep it out of client-side code and version control: anyone who has it can make requests, and spend, as you." }, "finish_reason": "stop", "index": 0 } ]}Call a saved agent
Section titled “Call a saved agent”An agent you saved in the console can be called by name from your own code. Send the same request, with "agent:" and the agent’s name as the model:
curl https://api.oraicle.me/v1/chat/completions \ -H "Authorization: Bearer $ORAICLE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "agent:Markets check", "messages": [{ "role": "user", "content": "How did NVDA close?" }] }'The agent answers with its own model, instructions and live data, and your messages are its input. The answer comes in the same shape as any chat completion, whole or streamed with "stream": true. A few things work differently from a plain call:
- The name is the one in your console. If no agent has exactly that name, one whose name differs only in capital letters is used. Only your own account’s agents can be called.
- The
toolsyou send are not used: the agent uses the live data you switched on for it. max_tokensis at most 4,000 for each model call, as for a run from the console.- Each call is paid from your wallet like a run from the console, counts toward the agent’s daily cap, and is kept in the agent’s runs in the console for 30 days, with your last message and the answer.
When a call can’t run, nothing is charged, and the answer says why:
| Status | Code | What it says |
|---|---|---|
| 400 | invalid_parameter |
messages: send at least one message, each with a role and content. |
| 402 | day_cap |
This agent has reached today’s spending cap. It runs again after midnight UTC. |
| 403 | agent_disabled |
We stopped this agent. If you think that is a mistake, write to abuse@oraicle.me. |
| 404 | agent_not_found |
No agent on this account has that name. |
| 409 | agent_name_ambiguous |
More than one of your agents has that name. Give each its own name in the console. |
| 409 | agents_not_open |
Agents are not open yet. |
An empty wallet, or a key at its spending limit, is refused as for any other call.