//native
type Cohere = {
apiKey: string;
};
/**
* Check API key
* Checks that the api key in the Authorization header is valid and active
*/
export async function main(auth: Cohere) {
const url = new URL(`https://api.cohere.com/v1/check-api-key`);
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + 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