Skip to main content

Basic Usage

The SDK provides two distinct methods for different use cases:

Event-Driven Conversational Method: chat.send()

Use client.chat.send() for chat applications with automatic conversation management and event-driven responses:

Direct API Method: chat.completions()

Use client.chat.completions() for direct API calls with manual control:

Configuration Options

Chat Configuration

When initializing the client, you can configure default chat settings:

Request Parameters

You can override defaults on a per-request basis:

Chat History Management

Conversation history is automatically managed when historySize is configured:

Message Format

Messages follow a structured format:

Event-Driven Responses

When using client.chat.send(), you can listen for events:

Error Handling

Handle errors gracefully with specific error types:

Best Practices

When to Use Each Method

Use chat.send() when:
  • Building conversational chat interfaces
  • You want automatic conversation history management
  • You need event-driven, real-time UI updates
  • You want automatic image generation and management
  • You prefer conversational turns with natural delays
  • Building simple chat applications
Use chat.completions() when:
  • You need direct API responses (await pattern)
  • Building non-conversational AI features (analysis, generation, etc.)
  • You want manual control over message arrays and history
  • You need streaming with custom chunk processing
  • You want to handle image prompts with your own generation service
  • Integrating with existing systems that expect synchronous responses

Configuration Tips

API Parameters:
  • Use temperature 0.7-0.9 for creative responses, 0.1-0.3 for factual responses
  • Set top_k to 20-40 for focused responses, higher for more diversity
  • Use repetition_penalty 1.1-1.2 to reduce repetition
  • Keep compliance enabled (true) in production for content safety
  • Adjust max_tokens based on your use case (default: 150)
SDK Features:
  • Set historySize to 10-30 for most conversational applications
  • Use reasoning: true for debugging or transparency (extracts <think> blocks)
  • Enable check_image_generation so AI analyzes its responses and creates image_prompt when images are requested or desired
  • Use autoTurn for natural conversation flow with realistic delays

Next Steps

Streaming Responses

Learn how to implement real-time streaming responses

Media & Vision

Add image and video analysis capabilities

Authentication Setup

Set up secure token provider authentication

Advanced SDK Features

Explore conversational turns and advanced features