OpenAI SDK Compatability

KrosAI Platform offers OpenAI SDK compatibility, allowing you to use familiar tools and libraries while benefiting from KrosAI's specialized features for African languages.

Getting Started

To use KrosAI with existing OpenAI integrations, simply change the base URL and API key in your configuration:

import openai

# Configure the client
client = openai.OpenAI(
    api_key="your-krosai-api-key",
    base_url="https://api.krosai.com/v1"
)

Sentiment Analysis

import openai

# Configure the client
client = openai.OpenAI(
    api_key="your-krosai-api-key",
    base_url="https://api.krosai.com/v1"
)

# Analyze sentiment
response = client.post(
    url="/sentiment",
    json={
        "text": "I am very happy with the service provided. Thank you!",
        "language": "english",
        "detailed": True
    }
)

result = response.json()
print(f"Sentiment: {result['results']['sentiment']}")
print(f"Confidence: {result['results']['confidence']}")
print(f"Detected language: {result['language']['detected']}")

Batch Sentiment Analysis

For analyzing multiple texts efficiently:

Translation

Chat Completions with Streaming

KrosAI also supports streaming responses for chat completions, just like the OpenAI API:

Compatibility Notes

While KrosAI maintains compatibility with the OpenAI SDK, there are some important differences to be aware of:

  1. Models: KrosAI uses its own models optimized for African languages. Replace OpenAI model names with KrosAI equivalents:

  • KrosMlingual2.0.1 for chat completions

  • KrosMLingualSTT1.0.0 for transcription and translation

  1. Additional Parameters: KrosAI supports extra parameters for working with African languages, such as specifying source language.

  2. Sentiment Analysis: This is a KrosAI-specific endpoint not available in the standard OpenAI API.

  3. Response Format: While we maintain compatibility with OpenAI's response structure, some fields may contain additional information specific to KrosAI services.

Error Handling

KrosAI follows the same error handling patterns as OpenAI:

API Key Management

For security best practices, we recommend storing your API key as an environment variable:

This compatibility layer makes it easy to transition existing applications to KrosAI while taking advantage of our specialized capabilities for African languages.

Last updated