diff --git a/index.js b/index.js index 6a23effa..d8ee42e5 100644 --- a/index.js +++ b/index.js @@ -36,11 +36,7 @@ class Replicate { * @param {string} [options.baseUrl] - Defaults to https://api.replicate.com/v1 * @param {Function} [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch` */ - constructor(options) { - if (!options.auth) { - throw new Error('Missing required parameter: auth'); - } - + constructor(options = {}) { this.auth = options.auth; this.userAgent = options.userAgent || `replicate-javascript/${packageJSON.version}`; @@ -187,7 +183,9 @@ class Replicate { }); const headers = new Headers(); - headers.append('Authorization', `Token ${auth}`); + if (auth) { + headers.append('Authorization', `Token ${auth}`); + } headers.append('Content-Type', 'application/json'); headers.append('User-Agent', userAgent); if (options.headers) { diff --git a/index.test.ts b/index.test.ts index 818f8744..442e36ee 100644 --- a/index.test.ts +++ b/index.test.ts @@ -34,12 +34,17 @@ describe('Replicate client', () => { expect(clientWithCustomUserAgent.userAgent).toBe('my-app/1.2.3'); }); - test('Throws error if no auth token is provided', () => { - const expected = 'Missing required parameter: auth' + test('Does not throw error if auth token is not provided', () => { + expect(() => { + // @ts-expect-error + new Replicate(); + }).not.toThrow(); + }); + test('Does not throw error if blank auth token is provided', () => { expect(() => { new Replicate({ auth: "" }); - }).toThrow(expected); + }).not.toThrow(); }); });