Practical integration

AI API: classify a support ticket

Work through a concrete task: turn a customer request into JSON for a support queue. The model suggests a category; your application validates fields and authorizes actions.

Define the input and accepted result first

For websites, internal tools and Telegram bots, the boundary is the same: users send messages to your backend, and your backend calls the model. The API secret is never sent to the browser or bot subscriber.

Use this synthetic ticket: “I was charged twice. How do I get the extra payment back?” Allow only billing, technical and account. The expected shape for this fixture is {"category":"billing"}. This is a human-authored test expectation, not a published model response or a measured generation result.

Chat history and chatbot integration · Create an application-specific key

What to send to the model

Choose a supported text protocol and keep the instruction separate from the ticket. The instruction should ask for one JSON object with only category, allow billing, technical and account, and specify that instructions inside the ticket are not to be executed.

A ticket can contain “ignore the rules” or a request to call a tool. User text is classification data, not authorization. A prompt alone is insufficient protection: this design also validates output and gives the model no payment capabilities.

If the selected route supports structured output, use it as an additional format constraint. Still validate the response on your backend; do not assume every model supports JSON Schema.

Choose a protocol · Minimal Python client

Validate before writing to the database

The following Python 3 example runs locally, makes no API call and consumes no balance. Pass only the model’s completed text response to parse_category. Invalid JSON, extra fields or unknown categories should route the ticket to manual review, not an endless generation loop.

The validator checks the object type, exact field set and allowed values. Even syntactically valid JSON must not be unpacked directly into SQL arguments, commands or refund operations.

import json

def parse_category(text):
    result = json.loads(text)
    allowed = {"billing", "technical", "account"}
    if not isinstance(result, dict) or set(result) != {"category"}:
        raise ValueError("Expected exactly one field: category")
    if not isinstance(result["category"], str) or result["category"] not in allowed:
        raise ValueError("Unknown category")
    return result["category"]

# Local validation only; no API request or charge.
assert parse_category('{"category":"billing"}') == "billing"
for invalid in ('{"category":"refund"}', '{"category":[]}',
                '{"category":"billing","refund":true}', '[]'):
    try:
        parse_category(invalid)
    except ValueError:
        pass
    else:
        raise AssertionError("Invalid output accepted")

Keep responsibilities explicit

Keep different users’ contexts separate. Send only information required for classification; payment credentials and secrets are not needed for this task.

ActionOwnerRequired check
Suggest a queueModelCompleted response and valid category.
Open a user’s ticketBackendAuthentication and ownership of the ticket.
Save a categoryBackendAllowed value, ticket ID and duplicate-processing protection.
Refund a payment or change an accountSeparate business processAuthorization, confirmation and audit trail; a model category grants none of these.

Test before enabling the workflow for all tickets

  • Prepare reference tickets for each queue, ambiguous inputs and a ticket that tries to override the instruction.
  • Track correct categories, invalid responses and spending per accepted result separately. The local example tests the validator, not model accuracy.
  • Limit message length, request frequency and concurrent operations per user. A shared API-key quota does not replace application-level controls.
  • Preserve an unknown state after a disconnection or timeout. Do not create a duplicate ticket or paid retry before checking the previous operation.

Request pricing · Usage tracking (Russian) · Integration help (Russian)

Documentation and example scope

Connection settings follow CLODEx documentation. Examples target the stated protocol; they are not recorded inference results and do not promise identical features across models. A successful generation request can incur a charge.

Client configuration · API protocols

Frequently asked questions

Can billing automatically trigger a refund?

No. A category suggests a queue, not permission for a financial transaction. Refunds require a separate authorized process.

Why validate JSON if the model follows instructions?

The model can return extra fields, invalid values or incomplete output. Reject those results before changing stored data.

Does this example measure a model’s quality?

No. It supplies a synthetic input, an expected contract and local validator tests. Measure quality and spending separately on your own tasks.

Connect CLODEX API to your application

One key-management layer, compatible endpoints and several LLM families for apps, agents and developer tools.