How to Access GPT-4o and Other Top AI Model APIs for Free
With the constant innovation in AI right now, I'm always looking for new ways to try out the latest models, especially APIs, so I can just plug them into my existing applications and see how they work. But if I'm just playing around, I don't want to bring up the credit card again to buy yet more API credits. I found a way to access some of the top models' APIs, including GPT-4o, for free. In this article, I'll show you how to get the API key and get it working.
Discovering Free AI Models on GitHub Marketplace
If you go to GitHub Marketplace, it actually has a section for models. You just need to get logged into your GitHub account, and it can just be a free account; you don't need to put your credit card or anything. You can access numerous models for free. They do have the new 01 models as well, but for those ones, you actually have to get on a waiting list to access them, so your mileage may vary on those ones. But they do have GPT-4o, GPT-4o mini, and also have the latest Llama 3.2 and Mistral as well. Let's try out GPT-4o.
Generating Your Free API Key
So, the first thing you want to do is get an API key. You just click the link and then select 'Get developer key'. From there, you can say 'Create new token.' I recommend just using the classic option here; it's actually easier to create the new token. Then, just give it a name and an expiration if you want to. However, where it says 'Select scopes,' actually don't select anything. Just leave it totally blank and select 'Generate token' because this token is really to identify what GitHub account you're using; it's not really giving it permissions to anything. From there, it just gives you the token, and you can just copy it.
Integrating the API into Your Application
Okay, so now we have the API key, we just have to add it to our application. The easiest way to figure out how this all works is if you just go to the playground under the model you're using. It just opens up a chat interface, but then you can just click on 'Code,' and now it gives us the actual code it's using to connect to the API. The nice thing about this is you'll notice it actually just uses the OpenAI packages. So basically, it works exactly the same as if you went to OpenAI directly and used their developer console, except this way it doesn't cost you anything.
Note: A key difference is the base URL, which is hosted on Azure from Microsoft. The base URL points to that.
They call the token we just got the 'GitHub token,' but you can really name this whatever you want in your environment variable. This is how you use it in JavaScript; you can also select other languages, as they have Python, C#, etc.
A Practical Example: Swapping API Keys
Now, I'm going to take an application that uses Groq and Llama 3.2 for its API and swap it out with this new setup. If we look at the existing application where I'm using Groq, the way I connect to it is by using createOpenAI
, which is actually part of the AI SDK from Vercel. If you actually wanted to use Llama in your application, I would stick with this method.
Now, I've switched it over. For my token, I just pasted in the token we got earlier, though a better practice is to use an environment variable. Then, we just change the endpoint to be that new one for Azure and set the model to gpt-4o
. That's really all the changes I had to make, because everything else works exactly the same as before since it's using the same OpenAI packages. This makes it nice because you can really just swap it out. For example, if you built something just using the OpenAI packages directly, you could really just change your token to this GitHub one and start using it for free.
Okay, let's run that and see how it works. If we ask about a solar panel, now it's going to go out to GPT-4o and come back with the answer for us. Everything else about my application remained the same. It still has the custom instructions about how it responds because this is supposed to be more like a customer support and sales chatbot. All that stuff still worked; I basically just swapped the model for this free one from GitHub.
Important Considerations and Alternatives
So, make sure you check out the models on GitHub Marketplace; it's a really good resource. They do have fairly low limits; for example, the GPT-4o one I used has a 50 requests-a-day limit, but that's still not bad for prototyping, and you can't beat the price. However, if you want to use the latest Llama model, I'd still stick with Groq because it's much faster and has much higher limits—very high limits—in terms of how much you can use for free.
Join the 10xdev Community
Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.