Edits history of script submission #12106 for ' Check Usage and Limits (deepl)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Deepl = {
      apiKey: string;
      baseUrl: string;
    };
    /**
     * Check Usage and Limits
     * Retrieve usage information within the current billing period together with the corresponding account limits.
     */
    export async function main(auth: Deepl) {
      const url = new URL(`${auth.baseUrl}/v2/usage`);
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "DeepL-Auth-Key " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago