JavaScript SDK
Authentication
Authenticate with the Cleanvoice JavaScript SDK.
Get your API key
Go to app.cleanvoice.ai/developer/api-keys and create a new key.
Initialize the client
The recommended approach is Cleanvoice.fromEnv(), which reads the CLEANVOICE_API_KEY environment variable automatically:
import { Cleanvoice } from '@cleanvoice/cleanvoice-sdk';
const client = Cleanvoice.fromEnv();You can also pass the API key explicitly:
import { Cleanvoice } from '@cleanvoice/cleanvoice-sdk';
const client = new Cleanvoice({
apiKey: process.env.CLEANVOICE_API_KEY,
});Custom base URL and timeout
const client = new Cleanvoice({
apiKey: process.env.CLEANVOICE_API_KEY,
baseUrl: 'https://api.cleanvoice.ai/v2',
timeout: 30000, // milliseconds
});timeout is in milliseconds.
Verify your key
const account = await client.checkAuth();
console.log(account);Returns your account information including remaining credits.
Usage in Next.js
Initialize the client once as a module-level singleton rather than recreating it inside each request handler:
// lib/cleanvoice.ts
import { Cleanvoice } from '@cleanvoice/cleanvoice-sdk';
export const cleanvoice = Cleanvoice.fromEnv();// app/api/clean/route.ts
import { NextResponse } from 'next/server';
import { cleanvoice } from '@/lib/cleanvoice';
export async function POST(req: Request) {
const { url } = await req.json();
const editId = await cleanvoice.createEdit(url, {
fillers: true,
long_silences: true,
});
return NextResponse.json({ editId });
}Never expose your API key in client-side code (browser bundles, React components without server boundaries, etc.). Always call Cleanvoice from server-side code only.