Building a serverless API on OCI with Java and Codex
I built a small serverless HTTP service to let an AI agent or other client add vendor records to an Oracle Autonomous AI Database without giving the caller direct database access.
The endpoint accepts a JSON POST, validates the fields, and inserts the record into the ACME.VENDORS database table. I built and deployed it from VS Code using Codex, Java 21, Docker, and Terraform. An end-to-end smoke test passed with a new vendor returning 200, and submitting the same vendor code again returning 409.
Below is the logical architecture diagram. Everything in the box was designed and created completely by Codex, specifically the Java code, documentation, test script, and IaC configuration.

Here is me demonstrating the invocation of the REST service through Postman.

And confirming that the record was successfully inserted into the database.

Application Overview
I wanted to create a REST API that's hosted in Oracle Cloud Infrastructure (OCI). A public OCI API Gateway receives the HTTPS request and invokes an OCI Function running Java 21. Though I've personally shifted more towards Python as my primary programming language, Java is still central and key within the Oracle ecosystem. The Function connects to an existing Autonomous AI Database using JDBC over TLS, without a wallet.
A successful insert returns the new vendor ID and an accepted status. The service returns 409 Conflict for a duplicate vendor_code, 400 for invalid requests, 413 for an oversized payload, and 500 for unexpected internal errors.
The API Gateway is public and does not require authentication. It applies a rate limit of 10 requests per second per client IP. The Function runs in a private subnet and sends outbound database traffic through a NAT Gateway. The Autonomous AI Database’s network ACL allows that fixed egress IP, and the database connection uses TLS.
Terraform manages the network, gateways, subnets, security lists, API Gateway, Functions application and Function, IAM invocation policy, and private OCIR repository, all completed written by Luna. The database itself existed before this project and was configured separately.
Function invocation logs are available in OCI Logging for troubleshooting, which, with the assistance of Luna, I had to end up using to find out why my test was failing (it was due to a wrong password I had used).

OCI Services Used
The table below lists all the OCI services used. Aside from the pre-existing Autonomous AI Database, the entire application architecture (i.e., which services to use) was designed by Luna. All the Terraform scripts were created by Luna, and it guided me on the commands to execute to get everything provisioned.
| OCI service | How the application uses it |
|---|---|
| API Gateway | Accepts public HTTPS requests at POST /vendor/v1/create, routes them to the Function, and limits traffic to 10 requests per second per client IP. |
| Functions | Runs the Java 21 vendor creation handler in a private subnet. |
| Autonomous AI Database | Stores vendor records in the ACME.VENDORS database table; the Function connects using TLS without a wallet. |
| Container Registry (OCIR) | Stores the private container image used by the Function. |
| Virtual Cloud Network (VCN) | Provides separate public and private subnets, routing, and security lists. |
| Internet Gateway | Supports public network access for the API Gateway subnet. |
| NAT Gateway | Gives Functions a fixed public egress IP for database ACL access. |
| Identity and Access Management (IAM) | Allows API Gateway to invoke the Function. |
| Logging | Stores Function invocation logs for troubleshooting. |
| Terraform | Provisions and updates the OCI network, API Gateway, Functions resources, IAM policy, and OCIR repository. |
Building with VS Code and Codex
I used VS Code with the Codex extension and selected GPT-6 Luna, which was the default. The work involved reading project requirements, editing Java and Terraform, building a container, deploying it, and diagnosing errors from the OCI logs. I personally have little to no experience with Docker and OCIR, yet here we are.

Luna seems to be a practical fit for this iterative coding exercise. OpenAI describes GPT-6 Luna as an efficient model for focused, high-volume tasks. More information can be found here on the GPT-6 Luna model.
There are other models available in Codex, depending on account access and rollout, such as GPT-6.1 Sol and GPT-6.1 Terra. Those could be alternatives for tasks calling for more advanced reasoning and capability levels. More information can be found here on these models in Codex. But here's a table comparing the models.
| OpenAI Model | Primary strength | Best suited for |
|---|---|---|
| GPT-6.1 Sol | Highest reasoning capability of these three | Complex coding, architectural decisions, debugging, refactoring, and multi-step development projects. |
| GPT-6.1 Terra | Balance of speed and intelligence | Everyday development, visual reasoning, UI work, precise computer interactions, and smaller code changes. |
| GPT-6 Luna | Speed and efficiency | Straightforward coding, boilerplate, documentation, simple bug fixes, and repetitive tasks. |
Token Usage and Cost
At the end of my exercise, the Codex interface within VS Code showed 134K of 258K tokens used, or about 52%. What does this even mean? After all, I've been using my free OpenAI account this entire time.

That token is a working-context measure which indicates how much conversation and project information was available to the model in that context. It is not a count of all tokens processed over the entire project, nor is it a bill.
I used the ChatGPT Free plan and its included Codex usage, without a separate API key or purchased credits. So the total cost of this exercise happened to end up being $0.00. Codex is included on Free plans, subject to usage limits. I don't know when I would've hit my free limit though.
GPT-6 Luna’s published API rates are $0.10 per million input tokens and $0.50 per million output tokens, with a lower rate for cached input. If 134K were all billable output tokens, the API-equivalent would be about $0.067. That's a hypothetical figure, so I'll reserve judgement until I see a bill in a future exercise.
The context meter doesn’t provide the breakdown required to calculate an API bill.
My Final Thoughts
Why did I embark on this exercise in the first place? I've been using Cline and Claude over the last year or two for my personal AI code generation, and have been pretty satisfied. I've also been waiting eagerly for Oracle Code Assist, but it seems that it's a bust and Oracle may no longer be investing in it (it still remains "in beta" since being announced over 2.5 years ago). Privately, folks from Oracle indicated that they're going to be falling back on Codex and OpenAI instead of the possibly defunked Oracle Code Assist.
So here I am playing with Codex and OpenAI/Luna.
In short, though the Cline user interface and interaction is far superior than Codex, OpenAI's GPT-6 Luna fared better with me than Claude's Sonnet 5.5 and Opus 5.5 models. This same exercise was giving me endless problems with Sonnet and I decided to pause the effort after spending $7 before switching to Luna.
As my initial reaction, I'm honestly impressed with Luna.