API Documentation

Documentation

  • API Access
  • Overview

API Resources

  • API Usage Statistics
  • Manage API Keys

Losi API Access

The Losi API allows you to integrate Losi's AI capabilities directly into your applications. Our API follows the OpenAI API format, making it easy to migrate existing applications or build new ones with our services.

Authentication

All API requests require authentication using an API key. You can create and manage your API keys in your profile settings.

To authenticate, include your API key in the Authorization header of your requests:

bash
curl https://losi.ai/api/v1/chat/completions \  -H "Content-Type: application/json" \  -H "Authorization: Bearer losi-your-api-key" \  -d '{    "model": "gpt-4o",    "messages": [{"role": "user", "content": "Hello, world!"}]  }'

API Key Management

Create an API Key

To create a new API key, navigate to your Profile Settings and enable API access. Then select the API tab and create a new API key with a name and permissions.

  • Your API key will only be shown to you once when it's created. Make sure to save it securely.
  • API keys are tied to your subscription plan and have usage limits accordingly.
  • Each API key has specific permissions that determine which API endpoints it can access.

Endpoints

Chat Completions

POST /api/v1/chat/completions

Create a chat completion for the given messages.

Request

json
{  "model": "gpt-4o",  "messages": [    {"role": "system", "content": "You are a helpful assistant."},    {"role": "user", "content": "Hello, world!"}  ],  "temperature": 0.7,  "max_tokens": 500,  "stream": false}

Response

json
{  "id": "chatcmpl-abc123",  "object": "chat.completion",  "created": 1677858242,  "model": "gpt-4o",  "choices": [    {      "index": 0,      "message": {        "role": "assistant",        "content": "Hello! How can I help you today?"      },      "finish_reason": "stop"    }  ],  "usage": {    "prompt_tokens": 18,    "completion_tokens": 9,    "total_tokens": 27  }}

Supported Models

Our API supports a variety of models including:

ModelDescriptionFeatures
gpt-4oOpenAI's GPT-4o modelVision, Tools
gpt-4o-miniSmaller version of GPT-4oTools
gpt-3.5-turboOpenAI's GPT-3.5 Turbo modelTools
losi-omegaLosi's flagship modelTools, Advanced Reasoning
claude-3.5-sonnetAnthropic's Claude 3.5 SonnetVision, Tools

For a complete list of available models, use the GET /api/v1/models endpoint.

Special Model: losi-omega

The losi-omega model is Losi's flagship AI model, built using a unique architecture called Unified Intelligence. It offers enhanced reasoning capabilities and native support for tools/function calling.

When using losi-omega through the API, the model's core system prompt is automatically injected, ensuring it maintains its friendly, helpful personality and proper tool usage capabilities. If you provide your own system message, the losi-omega system prompt will be appended to it rather than replacing it.

Example request with losi-omega:

json
{  "model": "losi-omega",  "messages": [    {"role": "user", "content": "What's the weather in London right now?"}  ],  "temperature": 0.7,  "tools": [    {      "type": "function",      "function": {        "name": "get_weather",        "description": "Get current weather in a location",        "parameters": {          "type": "object",          "properties": {            "location": {              "type": "string",              "description": "The city and state, e.g. London, UK"            }          },          "required": ["location"]        }      }    }  ]}

Parameters

ParameterTypeDescription
modelstringRequired. ID of the model to use.
messagesarrayRequired. Array of message objects representing the conversation history.
temperaturenumberControls randomness. Lower is more deterministic (0-2). Default: 0.7
max_tokensintegerMaximum number of tokens to generate.
streambooleanIf true, partial message deltas will be sent.
top_pnumberControls diversity via nucleus sampling. Default: 1
nintegerHow many completions to generate. Default: 1
stopstring or arrayUp to 4 sequences where the API will stop generating.
toolsarrayA list of tools the model may call.
tool_choicestring or objectControls when the model calls functions.
response_formatobjectFormat of the response. Default: text

Streaming

To receive a stream of partial completions, set stream: true. The response will be a stream of data in the Server-Sent Events format.

javascript
const response = await fetch('https://losi.ai/api/v1/chat/completions', {  method: 'POST',  headers: {    'Content-Type': 'application/json',    'Authorization': `Bearer ${apiKey}`  },  body: JSON.stringify({    model: 'gpt-4o',    messages: [{ role: 'user', content: 'Tell me a story' }],    stream: true  })});
const reader = response.body.getReader();const decoder = new TextDecoder();
while (true) {  const { done, value } = await reader.read();  if (done) break;    const chunk = decoder.decode(value);  // Process each chunk  console.log(chunk);}

Function Calling / Tools

Function calling allows the model to generate function calls as part of its output. This is useful for parsing structured information from user queries or calling external tools.

json
{  "model": "gpt-4o",  "messages": [    {"role": "user", "content": "What's the weather like in San Francisco?"}  ],  "tools": [    {      "type": "function",      "function": {        "name": "get_weather",        "description": "Get the current weather in a location",        "parameters": {          "type": "object",          "properties": {            "location": {              "type": "string",              "description": "The city and state, e.g. San Francisco, CA"            },            "unit": {              "type": "string",              "enum": ["celsius", "fahrenheit"]            }          },          "required": ["location"]        }      }    }  ]}

List Available Models

GET /api/v1/models

Lists the models available for your account based on your subscription plan.

Response

json
{  "object": "list",  "data": [    {      "id": "gpt-4o",      "object": "model",      "created": 1677610602,      "owned_by": "openai"    },    {      "id": "gpt-4o-mini",      "object": "model",      "created": 1677649963,      "owned_by": "openai"    }  ]}

API Keys Management

List API Keys

GET /api/v1/api-keys

List all API keys for your account.

Response

json
{  "data": [    {      "id": "key_abc123",      "key": "••••••••",       "name": "My API Key",      "created_at": "2023-06-01T12:00:00Z",      "last_used_at": "2023-06-02T15:30:00Z",      "permissions": ["chat.completions", "models.list"],      "expires_at": null,      "is_enabled": true    }  ]}

Create API Key

POST /api/v1/api-keys

Create a new API key.

Request

json
{  "name": "My New API Key",  "permissions": ["chat.completions", "models.list"],  "expires_at": "2024-12-31T23:59:59Z"}

Response

json
{  "data": {    "id": "key_xyz789",    "key": "losi-a1b2c3d4e5...",     "name": "My New API Key",    "created_at": "2023-06-03T09:00:00Z",    "last_used_at": null,    "permissions": ["chat.completions", "models.list"],    "expires_at": "2024-12-31T23:59:59Z",    "is_enabled": true  }}

Delete API Key

DELETE /api/v1/api-keys?id=key_abc123

Delete an API key by ID.

Response

json
{  "success": true}

API Usage Statistics

GET /api/v1/api-usage?start_date=2023-06-01&end_date=2023-06-30

Get API usage statistics for a specific date range.

Response

json
{  "data": {    "usage": [      {        "day": "2023-06-01",        "total_requests": 42,        "total_input_tokens": 1024,        "total_output_tokens": 512      },      {        "day": "2023-06-02",        "total_requests": 38,        "total_input_tokens": 896,        "total_output_tokens": 448      }    ],    "summary": {      "total_requests": 80,      "total_input_tokens": 1920,      "total_output_tokens": 960    }  }}

Error Handling

API errors are returned with an appropriate HTTP status code and a JSON response body that includes an error object.

json
{  "error": {    "message": "Invalid API key",    "type": "authentication_error"  }}

Common error types:

  • authentication_error - You provided an invalid API key
  • permission_error - Your API key does not have permission for this action
  • invalid_request_error - Your request was malformed or missing required parameters
  • rate_limit_error - You've exceeded your rate limit
  • insufficient_quota - You've exceeded your usage quota or lack access to the requested model
  • server_error - An unexpected error occurred on our servers

Rate Limits and Quotas

Rate limits and quotas vary based on your subscription plan:

  • Free tier: Limited to 1 API key and modest usage quota
  • Plus tier: Up to 2 API keys with increased usage limits
  • Pro tier: Up to 5 API keys with higher usage limits
  • Ultra tier: Up to 10 API keys with premium usage limits

Usage is measured in tokens, where:

  • 1 token is approximately 4 characters or 0.75 words
  • Input tokens and output tokens are counted separately
  • Different models have different token limits and pricing

SDK Support

Since our API is compatible with the OpenAI format, you can use the OpenAI SDK for most languages:

JavaScript/TypeScript

javascript
import OpenAI from 'openai';
const openai = new OpenAI({  apiKey: 'losi-your-api-key',  baseURL: 'https://losi.ai/api/v1'});
const response = await openai.chat.completions.create({  model: 'gpt-4o',  messages: [{ role: 'user', content: 'Hello, world!' }]});

Python

python
from openai import OpenAI
client = OpenAI(    api_key="losi-your-api-key",    base_url="https://losi.ai/api/v1")
response = client.chat.completions.create(    model="gpt-4o",    messages=[{"role": "user", "content": "Hello, world!"}])

Support

For questions or issues with the API, please contact our support team at or visit our .