Redeem a Voucher
const url = 'https://example.com/v1/credits:redeem';const options = { method: 'POST', headers: {'X-API-Key': '<X-API-Key>', 'Content-Type': 'application/json'}, body: '{"code":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/v1/credits:redeem \ --header 'Content-Type: application/json' \ --header 'X-API-Key: <X-API-Key>' \ --data '{ "code": "example" }'Redeem a credit voucher for your organization, as the billing page does.
Any member of the organization may redeem; a key needs credits:write.
Credits are the organization’s, so a workspace or restricted key is
refused. An unknown, used or expired code is a 400 with the reason.
Buying credits stays in the dashboard.
Authorizations
Section titled “Authorizations ”Request Body required
Section titled “Request Body required ”A voucher code, as the billing page takes it.
object
The voucher code to redeem
Example generated
{ "code": "example"}Responses
Section titled “ Responses ”The voucher’s credits were added
A redeemed voucher.
object
Credits the voucher added
The organization they were added to
Example generated
{ "credits_granted": 1, "account_id": "example"}An unknown, used or expired code, in the billing page’s words
Standard error response.
object
Error message describing what went wrong
Example generated
{ "detail": "example"}Invalid or missing API key
Standard error response.
object
Error message describing what went wrong
Example generated
{ "detail": "example"}The key lacks credits:write, or is a workspace key
Standard error response.
object
Error message describing what went wrong
Example generated
{ "detail": "example"}Validation Error
object
object
object
Example generated
{ "detail": [ { "loc": [ "example" ], "msg": "example", "type": "example", "input": "example", "ctx": {} } ]}