PRODUCTION USE CASE

LLM API for code generation

A product team receives a small feature ticket: add CSV export to an existing reporting page without changing its public API. The model gets the ticket, repository conventions, the affected files, and the test command. It returns a unified diff and the tests that prove the feature works.

Feature brief converted into a tested, reviewable code patch
LLM API for code generation

Production recipe

API, primary model, and failover configuration

Production choiceRecommendationWhy
APIPOST /v1/chat/completionsOpenAI-compatible server-side request
Primary modelgpt-5.6-terraTerra is the default because this workflow needs repository reasoning and usable patches, but not Sol-level effort on every ticket.
Fallback modelgpt-5.4Use gpt-5.4 for smaller isolated edits; escalate to Sol when the change crosses architecture boundaries or Terra fails the same acceptance test twice.
Escalation modelgpt-5.6-solUse only when the primary route fails the defined quality or complexity boundary
Output contractTask-specific text or patchA unified diff that applies cleanly, plus tests covering every acceptance criterion.
01
Scenario

Code generation in a production application

A product team receives a small feature ticket: add CSV export to an existing reporting page without changing its public API. The model gets the ticket, repository conventions, the affected files, and the test command. It returns a unified diff and the tests that prove the feature works.

LLMFly AI is used only for generation. The application still checks the patch in a disposable worktree, runs lint and tests, and sends failures back as a new message. Nothing is merged from the first response.

02
Architecture

How the code generation workflow operates

  • Retrieve the ticket, conventions, affected files, and test command.
  • Ask for a unified diff plus new or changed tests.
  • Apply the patch only inside a disposable worktree.
  • Run deterministic validation; return failures for one bounded repair attempt.
  • Send the passing patch to human review.
03
API request

Call gpt-5.6-terra through LLMFly AI

Send the request from your server. Replace the example content and placeholder tool schema with data and tools from your application.

request.exampleCopy-ready
curl https://app.llmfly.ai/v1/chat/completions \
  -H "Authorization: Bearer $LLMFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-terra",
    "messages": [
      {"role": "system", "content": "You are editing an existing repository. Return only a unified diff. Preserve public APIs, follow the supplied conventions, and include tests for every acceptance criterion."},
      {"role": "user", "content": "Add CSV export to the report page. Files and acceptance criteria follow below."}
    ]
  }'
04
Model choice

Why gpt-5.6-terra is the primary model

Terra is the default because this workflow needs repository reasoning and usable patches, but not Sol-level effort on every ticket.

Use gpt-5.4 for smaller isolated edits; escalate to Sol when the change crosses architecture boundaries or Terra fails the same acceptance test twice.

05
Acceptance

Acceptance checks for code generation

MetricPass condition
Build and test pass rateThe patch builds and all affected tests pass in isolation
Requirement coverageEvery acceptance criterion maps to a changed file or test
Unnecessary file changesNo unrelated file, dependency, or public interface changes without justification
Cost per accepted patchGeneration, retry, test, and review stay within the team's per-change budget
06
Failure handling

Failures to handle before deployment

  • Testing only toy prompts
  • Accepting code that compiles but misses requirements
  • Giving candidates unequal context
  • Ignoring review and repair cost
07
Output

Returned output and run records

A unified diff that applies cleanly, plus tests covering every acceptance criterion.

Record the model ID, request ID, token usage, retries, validation result, and final disposition for every production run.

Frequently asked questions

What should a code generation benchmark include?

Use tasks from your repositories with fixed requirements, test commands, and review criteria.

Should generated code be merged automatically?

Treat it as an untrusted patch. Build and test it in isolation, then require risk-appropriate review.

Is token price enough to compare coding APIs?

No. Compare cost per accepted patch after retries, tests, review, and repair.

Test this setup with your own inputs

Compare the primary and fallback models with the same requests, tools, and validation rules.

Compare models