AI API - Chat completions with tool calls (chat_completions)

AI API: Vectors, Images & LLM

The language model of the Opensolr API servers, in the request and answer format of the OpenAI chat completions API: messages, tools the model may call, JSON output, streaming.

Endpointhttps://api.opensolr.com/solr_manager/api/chat_completions
MethodPOST, a JSON body only (Content-Type: application/json)
Authemail and api_key in the JSON body: Authentication

01 · Body

index_nameRequired

Your index. Its owner's AI allowance is used.

messagesRequired

Up to 200 messages, roles system, user, assistant, tool, text only. At least one user message.

toolsOptional

Up to 128 function tools, as in the OpenAI format.

tool_choiceOptional

auto (default with tools), none, required, or one function by name.

max_tokensOptional

Longest answer, up to 8192. Default 1024. max_completion_tokens works too.

temperatureOptional

Up to 2. Anything below 0.7 is raised to 0.7.

top_p, stop, seedOptional

top_p 0.05 to 1, stop 1 to 4 strings, seed a number.

response_formatOptional

text, json_object, or json_schema with your schema.

streamOptional

true: the answer comes as Server-Sent Events, chunk by chunk, in the OpenAI format.

02 · Example

curl -s -X POST "https://api.opensolr.com/solr_manager/api/chat_completions" \
  -H "Content-Type: application/json" \
  -d '{"email": "YOUR_EMAIL", "api_key": "YOUR_API_KEY", "index_name": "my_index",
       "messages": [{"role": "user", "content": "What is the weather in Paris?"}],
       "tools": [{"type": "function", "function": {"name": "get_weather", "description": "Weather in a city",
         "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]}'

03 · Answer

{
    "status": true,
    "id": "chatcmpl-...",
    "object": "chat.completion",
    "created": 1791720310,
    "model": "...",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": null,
                "tool_calls": [
                    {
                        "id": "call_1",
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "arguments": "{\"city\": \"Paris\"}"
                        }
                    }
                ]
            },
            "finish_reason": "tool_calls"
        }
    ],
    "usage": {
        "prompt_tokens": 180,
        "completion_tokens": 22,
        "total_tokens": 202
    }
}

Run the tool yourself, add its answer as a tool message with the same tool_call_id, and call again. The model and its window: vdb_info gives them in llm. Values shown are an example.

Each answer counts one AI request. Every plan includes a monthly allowance of AI requests: API Quota, Pricing. The allowance used is the one of the account that owns the index.

04 · Errors

ERROR_JSON_BODY_REQUIREDHTTP 200

The body is not JSON.

ERROR_MESSAGES_REQUIRED, ERROR_USER_MESSAGE_REQUIREDHTTP 200

No messages, or no user message.

ERROR_INVALID_MESSAGE_ROLE, ERROR_TEXT_MESSAGES_ONLY, ERROR_INVALID_TOOL_CALLSHTTP 200

A message the format does not allow.

ERROR_INVALID_TOOLS, ERROR_INVALID_TOOL_CHOICE, ERROR_INVALID_RESPONSE_FORMAT, ERROR_INVALID_STOPHTTP 200

A field that does not follow the format.

ERROR_CHAT_TOO_LONGHTTP 200

The conversation does not fit the window of the model.

ERROR_CHAT_REQUEST_REFUSEDHTTP 200

The model refused the request; detail says why.

VECTOR_NOT_ALLOWED, ERROR_AI_MONTHLY_QUOTA_EXCEEDEDHTTP 200

AI is off on the plan of the index owner, or the allowance is used up.

ERROR_LLM_UNAVAILABLE, AI_GENERATION_FAILEDHTTP 200

The model did not answer. Retry.

WRONG_API_HOSTHTTP 404

Called on opensolr.com.

ERROR_AUTHENTICATION_FAILEDHTTP 403

The email and API key do not match.

05 · Related

The whole chat bot of your site in one call, searches and lookups included: assistant_chat.

Every error code and HTTP status of the API: API errors. Calls per minute and per hour: Rate limits.