Use cases

Choosing an AI API for classification and structured output

Tagging tickets, extracting fields or routing messages needs short, machine-readable JSON answers at very high volume — so the cheapest model that stays accurate wins.

What classification and structured output needs

  • JSON output your code can parse
  • Very low cost per item
  • Consistent labels

Models that fit

ModelMakerList price (in / out per 1M)Through SomnusWhy
DeepSeek V4 FlashDeepSeek$0.22 / $0.66$0.11 / $0.33lowest cost per item
Gemini 3.8 FlashGoogle$0.75 / $3.75$0.38 / $1.88cheap and consistent
Claude Haiku 4.5Anthropic$1 / $5$0.5 / $2.5more careful labelling

Somnus column uses the minimum 2× credit; larger top-ups go further.

Cost example

1,000 requests of about 1,500 input and 400 output tokens on DeepSeek V4 Flash cost about $0.59 at list price — roughly $0.30 with Somnus credit.

Tips

  • Request JSON output and validate it with a schema.
  • List the allowed labels explicitly.
  • Test on a sample of 100 items before running thousands.

Common mistakes

  • Free-text answers that break your parser.
  • Paying flagship prices for a yes/no decision.

Example

python
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["SOMNUS_API_KEY"],
    base_url="https://gateway-production-c837.up.railway.app/v1",
)

resp = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[
      {"role": "system", "content": "Reply only with JSON."},
      {"role": "user", "content": "Classify this message as billing, bug, or feature_request: 'I was charged twice.'"}
    ],
    response_format={"type": "json_object"},
)
print(resp.choices[0].message.content)

Questions

What is the cheapest model for classification and structured output?

Of the models suggested here, DeepSeek V4 Flash has the lowest list price ($0.22 / $0.66 per 1M tokens). Test it on your own examples before committing.

Can I switch models later?

Yes. With Somnus you change the model name; the rest of the code stays the same.

Run this code with free credit

Create an account and get $5 of free API credit — enough to try every example on this page.

Get $5 free credit

Related

Browse more: Alternatives · Compare · Use cases · Developers · Solutions · Tools

WindowsStart with $5 free