Skip to main content

Constructor

Create a new instance of the Thred API client.
const client = new ThredClient(config: ThredConfig)

Parameters

config
ThredConfig
required
Configuration object for the Thred client

Examples

Basic Configuration

import { ThredClient } from '@thred/sdk';

const client = new ThredClient({
  apiKey: 'your-api-key-here'
});

Custom Model and Timeout

import { ThredClient } from '@thred/sdk';

const client = new ThredClient({
  apiKey: 'your-api-key-here',
  defaultModel: 'gpt-4-turbo',
  timeout: 60000 // 60 seconds
});

Environment Variables

import { ThredClient } from '@thred/sdk';

const client = new ThredClient({
  apiKey: process.env.THRED_API_KEY!,
  defaultModel: 'gpt-4',
  timeout: 45000
});

Configuration Best Practices

API Key Security

  • Never hardcode your API key in source code
  • Use environment variables or secure configuration management
  • Keep your API key confidential and rotate it regularly
// Good
const client = new ThredClient({
  apiKey: process.env.THRED_API_KEY!
});

// Bad - don't do this!
const client = new ThredClient({
  apiKey: 'sk_live_abc123...'
});

Model Selection

Choose your default model based on your use case:
  • gpt-4: Use for complex reasoning, detailed analysis, or when quality is paramount
  • gpt-4-turbo: Balance of speed and capability for most production use cases
  • gpt-3.5-turbo: Use for simple tasks, high-volume requests, or cost optimization

Timeout Configuration

Set timeouts based on your expected response times:
  • Short timeouts (10-20s) for simple queries
  • Medium timeouts (30-45s) for standard use cases (default)
  • Long timeouts (60s+) for complex analysis or streaming responses

Error Handling

The constructor will throw an error if the API key is not provided:
try {
  const client = new ThredClient({
    apiKey: '' // Empty API key
  });
} catch (error) {
  console.error('Failed to create client:', error.message);
  // Output: "API key is required"
}

Build docs developers (and LLMs) love