# Synor Compute SDK for JavaScript/TypeScript Access distributed heterogeneous compute at 90% cost reduction. ## Installation ```bash npm install synor-compute # or pnpm add synor-compute # or yarn add synor-compute ``` ## Quick Start ```typescript import { SynorCompute, Tensor } from 'synor-compute'; const client = new SynorCompute('your-api-key'); // Matrix multiplication on GPU const a = Tensor.random([512, 512]); const b = Tensor.random([512, 512]); const result = await client.matmul(a, b, { precision: 'fp16', processor: 'gpu' }); console.log(`Execution time: ${result.executionTimeMs}ms`); console.log(`Cost: $${result.cost}`); ``` ## Tensor Operations ```typescript // Create tensors const zeros = Tensor.zeros([3, 3]); const ones = Tensor.ones([2, 2]); const random = Tensor.random([10, 10]); const randn = Tensor.randn([100]); // Normal distribution // From array const data = Tensor.from([1, 2, 3, 4, 5, 6], [2, 3]); // Operations const reshaped = data.reshape([3, 2]); const transposed = data.transpose(); ``` ## Matrix Operations ```typescript // Matrix multiplication const result = await client.matmul(a, b, { precision: 'fp16', processor: 'gpu', strategy: 'speed' }); // 2D Convolution const conv = await client.conv2d(input, kernel, { stride: [1, 1], padding: [1, 1] }); // Flash Attention const attention = await client.attention(query, key, value, { numHeads: 8, flash: true }); ``` ## LLM Inference ```typescript // Single response const response = await client.inference('llama-3-70b', 'Explain quantum computing', { maxTokens: 512, temperature: 0.7 }); console.log(response.result); // Streaming response for await (const chunk of client.inferenceStream('llama-3-70b', 'Write a poem')) { process.stdout.write(chunk); } ``` ## Configuration ```typescript const client = new SynorCompute({ apiKey: 'your-api-key', baseUrl: 'https://api.synor.io/compute/v1', // or localhost:17250 for local defaultProcessor: 'gpu', defaultPrecision: 'fp16', defaultStrategy: 'balanced', timeout: 30000, debug: false }); ``` ## Job Management ```typescript // Submit async job const job = await client.submitJob('matmul', { a, b }); // Poll for status const status = await client.getJobStatus(job.jobId); // Cancel job await client.cancelJob(job.jobId); ``` ## Error Handling ```typescript import { SynorError } from 'synor-compute'; try { const result = await client.matmul(a, b); } catch (error) { if (error instanceof SynorError) { console.error(`API Error: ${error.message} (${error.statusCode})`); } } ``` ## TypeScript Support Full TypeScript support with exported types: ```typescript import type { Tensor, ProcessorType, Precision, BalancingStrategy, JobStatus, SynorConfig, MatMulOptions, InferenceOptions, JobResult } from 'synor-compute'; ``` ## Testing ```bash npm test # or pnpm test ``` ## License MIT