Skip to main content

Credits Billing

Monetization Configs

To enable monetization, define monetization in your config as shown below:

tasks:
- name: EXAMPLE_TASK
publish: true
monetization:
toolId: myToolId # ID used for credit tracking; contact the Monetization team to obtain one

Tool Usage Amount

It is possible to specify the total amount of tool usage to be billed by providing usageAmount parameter in options.

@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {

async options(exampleCommand: ExampleCommand): Promise<TaskOptions> {
const toolId = exampleCommand.model === 'model1' ?
'model1_tool_id' : 'default_toolId';

const totalUsageAmount = countTotalToolUsageAmount();

return {
monetization: {
toolId
},
usageAmount: totalUsageAmount,
}
}
}
usageAmount

usageAmount can be set dynamically based on your usage logic and defaults to 1 if not provided.

Ensure your project uses version 3.7.0 or higher of @picsart/pa-pluggable-workers-core to send usageAmount from options.

Partial Confirmation

When submitting results, include partialUsageAmount to indicate the exact amount of tool usage to be charged. This lets you confirm only the number of times the tool was used successfully, rather than charging for all attempts.

@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async processTask(taskCommand: ExampleCommand): Promise<TaskResult> {
const successfulUsages = countSuccessfulGenerations();

return {
result: { exampleKey : 'exampleValue' },
meta: {
partialUsageAmount: successfulUsages,
}
};
}
}

For example, if usageAmount is set to 3 but only 2 out of 3 tool executions succeed, you can set partialUsageAmount to 2 to charge for just those successful uses.

note

Ensure your project uses version 4.2.0 or higher of @picsart/pa-pluggable-workers-core to send meta in response.

warning

The lesser value between partialUsageAmount and usageAmount will be applied. Please ensure to send accurate values for both to avoid unexpected outcomes.

warning

If the user’s balance can’t cover the number of uses specified by usageAmount, the /submit or /execute request will fail with a 402 error.