Coding
AI coding with your own API key: a student guide
Bring your own OpenAI, Anthropic or Gemini key into GroutCode. Pay-per-token, no subscription lock-in. Learn which models suit which coding tasks.
Anish Menon · CEO & Founder, Grout
· 5 min read

You can bring your own API key to an AI coding assistant by selecting a platform that supports custom keys, purchasing token credits directly from a model provider like OpenAI or Anthropic, then pasting your key into the assistant's settings. GroutCode's AI coding agent supports nine providers: OpenAI, Anthropic, Google Gemini, OpenRouter, Groq, Together, xAI, Cerebras and any custom OpenAI-compatible gateway.
What an API key is and how billing works
An API key is a private credential that authenticates your requests to a model provider. When you sign up for an account with OpenAI, Anthropic or Google, you can generate a key in their developer console. The key is a long string of letters and numbers that acts as a password, authorising the provider to charge your account for each token you use.
Billing is pay-per-token. A token is roughly three-quarters of a word in English. When you send a prompt and receive a response, the provider counts the input tokens and the output tokens, then charges a rate per million tokens. Input is usually cheaper than output. A model like GPT-4o might cost a few cents per thousand input tokens and a bit more per thousand output tokens. A long code review or a multi-file refactor can run to tens of thousands of tokens, so a typical session costs between a few cents and a dollar or two.
Most providers let you set spending limits in your account dashboard. You add a hard cap, and the API stops serving requests when you hit it. This prevents surprise bills. Check your provider's billing section: OpenAI calls it usage limits, Anthropic has spending limits, and Google offers budget alerts.
Adding your key to a coding assistant
In GroutCode, you add a key in the AI settings panel. The key is stored encrypted per account and sent with each request to the chosen provider. Once you add a key, models from that provider appear in a "Your keys" group in the model picker. When you select one of those models, requests do not consume Merits, the internal currency that otherwise meters cloud model access. You pay the provider directly, and the assistant simply relays the request with your key attached.
This arrangement gives you control over which model you use and how much you spend. If you prefer a specific provider's billing terms or have existing credits, bring-your-own-key avoids a second subscription or top-up layer.
Which model for which task
Not every model suits every coding task. Larger frontier models like GPT-4o, Claude 3.5 Sonnet or Gemini Pro excel at complex refactoring, debugging subtle logic errors and generating entire classes from a specification. They understand nuance and handle multi-file context well. They are also the most expensive per token.
Mid-tier models like GPT-4o mini, Claude 3.5 Haiku or Gemini Flash are cheaper and faster, often completing a request in a second or two. They work well for simpler tasks: writing a short function, explaining a compiler error, formatting code or generating boilerplate. For repetitive work, a smaller model can save you half the cost with little loss in quality.
Specialist fast models from Groq or Cerebras run at very high inference speeds. They are useful when you need a quick suggestion or autocompletion-style fills, though they may lack the reasoning depth of frontier models.
OpenRouter aggregates dozens of models under one API, so a single key gives you access to a range of options. This can simplify billing if you want to experiment across providers without managing multiple keys.
Local models run on your own machine and cost nothing per token after the initial download. A capable GPU can serve a quantised 7B or 13B parameter model at reasonable speed. Local models are slower and less accurate than cloud frontier models, but they never leak your code to a remote server and they work offline once downloaded. If you are working on proprietary code or have unreliable internet, a local model is a pragmatic fallback.
Free tiers and student credits
Many providers offer free trial credits when you sign up. Anthropic sometimes gives new accounts a small credit to test Claude. Google Cloud includes free Gemini quotas. GitHub's student pack has occasionally bundled cloud credits. These offers change frequently, so check the provider's pricing page or student programme before you assume a free tier still exists.
If you do find credits, use them to test a few models and measure how much a typical session costs you. Once you know your usage pattern, you can decide whether to top up or switch to a cheaper model.
Key safety
An API key is as sensitive as a password. If someone obtains your key, they can run up charges on your account. Never paste a key into a public GitHub repository, a shared chat or a forum post. If you accidentally commit a key to a repo, rotate it immediately in the provider's console. Most providers detect leaked keys in public repositories and automatically revoke them, but you should not rely on this.
Store keys in environment variables or a secure credential manager, not in plain text files. If you share code with a team, use placeholder variables and document where to obtain a key, rather than including the key itself.
If you suspect a key has been exposed, generate a new one and delete the old one. Providers typically let you create multiple keys and revoke individual keys without affecting others.
Comparing assistants that support your own key
Several coding assistants now accept custom keys. Cursor is a popular option that integrates into an editor fork, but some students prefer a standalone tool that does not replace their existing IDE. GroutCode offers an alternative to Cursor with offline-capable tools, compiler-checked practicals and the ability to bring keys from nine providers.
When you evaluate an assistant, check which providers it supports, how it stores keys and whether it offers local models as a fallback. A good assistant should encrypt keys at rest, let you switch providers without re-entering credentials and clearly separate metered usage from your own key usage.
Practical workflow
Start with a free trial or small credit to test a frontier model on a real task. Measure the token count and cost. If the task is routine, drop down to a mid-tier model and compare the output quality. Once you settle on a model, set a spending cap at the provider.
GroutCode shows the selected model and provider before you send a prompt, so you always know which key will be charged. If you run out of credits mid-session, you can switch to a local model or top up your provider account without losing your work.
Bringing your own key turns an AI coding assistant into a direct extension of your provider account. You pay only for what you use, you control the budget and you choose the model that fits the task. For students and practitioners who want transparency and flexibility, it is the most honest way to use AI in code.