GPT API: using GPT-6 models in your own code

Developers reach GPT models through OpenAI's own API or through routers such as OpenRouter. This guide shows the first request, the model ids, the reasoning settings and what each model costs.

5 min readUpdated

Two ways to call GPT from your code

If you want GPT inside your own app, script or spreadsheet, you need API access. There are two common routes:

  • OpenAI's API at https://api.openai.com/v1. You sign up on OpenAI's platform, add billing, create a key and call models such as gpt-6-luna or gpt-6.1-terra directly.
  • OpenRouter at https://openrouter.ai/api/v1. One key gives you GPT alongside models from other companies, with the same request format for all of them. GPT model ids carry an openai/ prefix, for example openai/gpt-6-luna.

Both bill per token, the small text chunks a model reads and writes. Input (your prompt) and output (the answer) are priced separately, and output is always the more expensive side. Reasoning tokens, the hidden "thinking" a model does before answering, are billed as output too.

A quick note before you start: GPT.me does not offer a public API. Our chat is a website for people. For code, use one of the two routes above.

Current GPT prices

Prices per million tokens for the current GPT-6 models, as listed on OpenRouter; OpenAI's own API lists the same base prices.

ModelAPI id (OpenAI)InputCached inputOutput
GPT-6 Lunagpt-6-luna$0.10$0.01$0.50
GPT-6.1 Terragpt-6.1-terra$1$0.05$5
GPT-6 Solgpt-6-sol$2$0.20$10
GPT-6.1 Solgpt-6.1-sol$2$0.10$10
GPT-6 Astragpt-6-astra$10$1$50

OpenRouter list price, Nov 2026. All five models accept text and images, return text, and have a context window of 1,050,000 tokens with up to 128,000 output tokens. When a single prompt goes over 272,000 tokens, OpenRouter's listing doubles the input price and raises the output price by half for that request. OpenRouter also lists "pro" variants of each model, which run the same model in a mode that spends far more reasoning tokens.

Calling OpenAI directly

OpenAI offers two endpoints for text: the newer Responses API, which its GPT-6 documentation uses throughout, and the older Chat Completions endpoint, which still works for simple chats. Create a key on the platform, store it in an environment variable called OPENAI_API_KEY, then send a request. With curl:

curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-luna",
    "reasoning": { "effort": "none" },
    "input": "List three uses for a paper clip, one line each."
  }'

The reply is JSON; the generated text sits in the output array. The official Python library pulls it out for you:

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY

result = client.responses.create(
    model="gpt-6.1-terra",
    reasoning={"effort": "low"},
    input="Is 391 a prime number? Explain in two sentences.",
)
print(result.output_text)

Install it with pip install openai. The same library also exists for JavaScript and several other languages.

Calling GPT through OpenRouter

OpenRouter speaks the Chat Completions format, so most OpenAI-compatible code works after you change the base address, the key and the model id. Its quickstart covers the details. A plain JavaScript example with no extra libraries:

const OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions";

const payload = {
  model: "openai/gpt-6-luna",
  max_tokens: 800,
  reasoning: { effort: "low" },
  messages: [
    { role: "system", content: "Answer briefly and plainly." },
    { role: "user", content: "What is the difference between RAM and storage?" },
  ],
};

const key = process.env.OPENROUTER_API_KEY;

const res = await fetch(OPENROUTER_URL, {
  method: "POST",
  body: JSON.stringify(payload),
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
});

const body = await res.json();
const text = body.choices?.[0]?.message?.content;
console.log(text ?? body);

Run it with Node 18 or newer, which has fetch built in, saved as a .mjs file so that top-level await works. If no text comes back, the script prints the whole response instead: OpenRouter returns an error field with a readable message, for example when the key is wrong or the account has no credit left.

The model pages on OpenRouter, for example GPT-6 Luna and GPT-6.1 Terra, show current prices, providers and supported parameters.

Settings that trip people up

  • Reasoning effort. GPT-6 Luna, GPT-6 Sol and GPT-6.1 Terra accept none, low, medium, high, xhigh and max, and default to medium on OpenRouter. GPT-6.1 Sol and GPT-6 Astra always reason and cannot be set to none. In the Responses API the field is reasoning.effort; in Chat Completions it is reasoning_effort.
  • Temperature. OpenAI's guide says temperature and top_p are not supported while reasoning is on, so remove them unless effort is none. Older code that sets temperature can fail with an error.
  • Output cap. Reasoning uses part of the token budget. If you set a low max_tokens with high effort, the model can run out before it writes the visible answer.
  • Tools. OpenAI's model pages note that function calling for GPT-6.1 Terra needs the Responses API. If tools behave oddly through Chat Completions, switch endpoints.

Keeping the bill small

  1. Start with Luna. At a tenth of Terra's price it handles summaries, extraction, classification and short replies well. Move up only for tasks it gets wrong.
  2. Keep effort low. Each step up in reasoning effort usually means more hidden output tokens. Use none or low for simple jobs.
  3. Reuse your prefix. Cached input costs a tenth of fresh input or less. Put long, unchanging instructions at the start of every prompt so repeated requests can hit the cache.
  4. Stay under 272,000 tokens per prompt when you can, to avoid the long-context surcharge.
  5. Set a spending limit in your account dashboard so a bug in a loop cannot run up a large bill.
  6. Trim the history you send. Every request pays for the whole conversation again. Keep only the turns the model needs, or replace old ones with a short summary.

A rough way to estimate cost: one token is about three quarters of an English word. A question and answer of a few hundred words each come to roughly a thousand tokens in total, so the price per request is the per-million figure from the table divided by a thousand, plus any reasoning tokens. Watch the usage field in each response to see the real numbers for your own prompts.

For coding help beyond the API itself, see our guide to GPT for coding and the page for developers. To test a prompt before you write any code, try it in our chat with GPT-6 Luna first.

FAQ

Is the GPT API free?

No. OpenAI and OpenRouter both bill per token. A short test with GPT-6 Luna costs a fraction of a cent, but you still need an account with billing set up.

Should I use OpenAI directly or OpenRouter?

Go direct if you only need GPT and want every OpenAI feature first. Choose OpenRouter if you want to switch between GPT, Claude, Gemini and other models with one key and one bill.

Which model should I start with?

GPT-6 Luna for speed and price, GPT-6.1 Terra for better writing, image understanding and harder reasoning, and GPT-6.1 Sol or GPT-6 Astra only for the most demanding coding and analysis.

Does GPT.me have an API?

No. GPT.me is a free chat website. For programmatic access, use OpenAI's API or OpenRouter.

Got a question? Ask it now

No account and no download. Open the chat, type what is on your mind, and the answer starts appearing in a second or two.

Start chatting