Skip to main content

Overview

The SDK provides a streamlined interface for making requests to the Secton API. This section covers the core request methods and their configurations.
Instantiate the client and use the ask() method for a single query:
import { createClient } from 'secton';

const client = createClient({ apiKey: 'your-api-key' });

const response = await client.ask('What is the capital of France?');
console.log(response);
For multi-turn conversations, utilize the chat() method:
const response = await client.chat([
  { role: 'user', content: 'Tell me a joke.' }
]);
console.log(response);
These methods are suitable for interactions without the need for context management.
For real-time interactions, the stream() method allows you to receive chunks of data as they are generated:
const stream = await client.chat.stream([
  { role: 'user', content: 'Explain quantum mechanics.' }
]);

for await (const chunk of stream.stream) {
  console.log(chunk);
}
You can also apply transformations to the stream:
import { mapStreamIterator } from 'secton';

const transformedStream = mapStreamIterator(
  stream.stream,
  chunk => chunk.toUpperCase()
);

for await (const chunk of transformedStream) {
  console.log(chunk);
}
This approach is ideal for apps requiring real-time data processing.
I