This article is for API providers. For more information on using credits as an API consumer, check out this article.In the JoJ API you can set the amount of credits to be spent for each request.
1. Fixed credit usage
To do this, you first need to specify the maximum number of credits per request from the endpoint details in Studio. This amount is displayed to API consumers and is determined as the maximum amount by our gateway. You cannot specify more credit spending than this amount in any request. This is convenient for you to set different pricing between different endpoints. By default, requests with a request code of 5xx are considered unsuccessful and no credits are spent.Set up custom credit spending
To specify a credit spend for a request, you need to return a header in your side. For example, if you want 3 credits to be spent, you would return a header like this:Adjusting credit in Server-Sent Events (SSE) responses
To determine credit usage in SSE responses (must becontent-type: text/event-stream), you can send a message like the following.
2. Flexible credit usage
Flexible credit usage is useful in cases where credit consumption is directly dependent on the content of the API response. In flexible pricing, there is no upper credit limit, and you can allocate as many credits to users as you wish. To do this, you must send theX-Jojapi-Credits-Used header or SSE message from your side. The value you send must not be less than zero.