Register your interest: Tag @Cody, get an agent
BlogEngineering

Google Gemini API: models, requests, and migrating from PaLM

What replaced PaLM, how the request shape differs, choosing between the Pro and Flash model families, and the capabilities that make Gemini worth the migration work.

Aymeric ZhuoAymeric Zhuo10 min read

Summarize with AI

Google Gemini API: models, requests, and migrating from PaLM
On this page

The PaLM API is gone, and anything still written against it stopped working rather than degrading gracefully. Gemini is what replaced it, and the migration is more than a change of endpoint: the request structure differs, the model families are organized around a different trade-off, and several capabilities have no PaLM equivalent at all.

This page covers the API itself, which is to say what you send, what comes back, and which model to send it to. For creating an account, generating keys, and understanding the free tier's quotas, see setting up a Gemini API account.

What we'll cover

What happened to PaLM

PaLM was Google's earlier generation of language model, exposed through a generativelanguage API with text-bison and chat-bison model identifiers. Google announced its deprecation and subsequently shut the endpoints down, directing developers to the Gemini API in its place.

The shutdown was not gradual. Applications calling the PaLM endpoints receive errors rather than degraded responses, so there is no version of this where an old integration limps along. If you are reading this because something broke, that is the cause.

The identifiers are the quickest diagnostic. A request naming text-bison, chat-bison, or embedding-gecko is a PaLM request and needs migrating. Anything naming a gemini- model is already on the current API.

How the request shape changed

The differences go beyond renaming, and the ones that cause the most trouble are structural.

Content is a list of parts rather than a string. PaLM took a prompt as text. Gemini takes a contents array, where each entry has a role and a list of parts, and each part may be text, an image, or other media. Even a plain text request wraps the string in that structure, which is the single most common source of migration errors.

Conversation history is explicit. Rather than a separate examples or context field, the exchange is expressed as alternating user and model roles in the same contents array. This is closer to how other current APIs work and makes multi-turn conversations more natural to express.

System instructions have their own field. PaLM had a context string that was effectively prepended. Gemini provides a dedicated system instruction parameter, which is treated distinctly from the conversation and is where persistent behaviour belongs.

Safety settings are configurable per request. Gemini exposes categories with adjustable thresholds, and requests can be blocked by these filters. A response with no content and a block reason is a safety filter rather than an error, and code migrated from PaLM frequently fails to check for it, producing a confusing empty result.

Generation parameters were renamed. Temperature survives; several others moved into a generationConfig object with different names. The parameter you want usually exists, under a different label.

The practical consequence is that a migration is a rewrite of the request construction rather than a search and replace on the model name. It is not difficult work, and it is more than an afternoon on anything substantial.

Choosing between the model families

Gemini is organized around a straightforward trade-off, and the specific version numbers change often enough that the families matter more than the identifiers.

Pro models are the more capable option: better at multi-step reasoning, complex instructions, nuanced judgement, and difficult code. They cost more per token and respond more slowly. Use them where the task genuinely requires reasoning and where being wrong is expensive.

Flash models are optimized for speed and cost. They handle classification, extraction, summarization, and straightforward generation extremely well, at a fraction of the price and latency. Most production workloads are Flash workloads, and teams routinely overspend by defaulting to Pro out of caution.

The pattern worth adopting is to start on Flash and measure. Build a set of representative examples with known good answers, run them through Flash, and move only the cases that disappoint to Pro. Applications frequently end up mixed, with Flash handling volume and Pro reserved for the hard path, which is the right shape.

Gemini's context windows are generous across both families, which changes what is practical. Whole documents, long conversations, and substantial codebases fit in a single request, which removes a great deal of chunking machinery that shorter windows require. Because you pay per token, a large window is permission rather than encouragement.

For exact model identifiers and their current capabilities, Google's own model documentation is the only reliable source. Any list written in an article is out of date within a few months.

Capabilities PaLM never had

Several of these are the actual reason to migrate, beyond the endpoint having been turned off.

Native multimodality. Images, audio, video, and PDFs can be sent as parts of a request alongside text. This is not a separate vision endpoint but the same conversation carrying different media, which makes workflows over scanned documents and screenshots considerably simpler to build.

Very long context. Entire documents and long transcripts fit in one request, so retrieval and chunking become optional rather than mandatory for medium-sized corpora.

Structured output. A response schema can be supplied, and the model returns conforming JSON. This replaces the prompt-and-hope approach with something you can rely on, and it removes most output parsing code.

Function calling. The model can be given tool definitions and will indicate which to call with what arguments, which is how you connect it to systems that actually do things rather than just describing them.

Context caching. Where a large context is reused across many requests, such as a long document being asked about repeatedly, caching it reduces both cost and latency substantially. This is worth knowing about early, because it changes the economics of document-heavy applications.

Migrating an existing integration

Inventory what you call. Find every PaLM model identifier in the codebase. Prompt templates and configuration files hide more of these than the application code does.

Rebuild the request construction first. The contents structure is the substantive change. Get one call working end to end before touching the rest, because everything else follows the same pattern.

Keep your prompts and test them. Prompts generally transfer, and they do not always behave identically. Assemble a set of representative inputs with known good outputs before you start, run them after, and compare. This is the step that catches the quiet regressions.

Handle safety blocks explicitly. Check for a block reason on every response. A prompt that PaLM answered may be filtered by Gemini, and unhandled this presents as an empty response with no explanation.

Adopt structured output where you were parsing text. Any code extracting JSON from a text response with a regular expression should be replaced with a response schema. It is less code and it stops failing at three in the morning.

Review your model choice rather than mapping it. The PaLM model you used was chosen from a different menu. Start on Flash and measure rather than assuming the Pro equivalent is the right destination.

Where the integration is a business workflow rather than an application feature, there is a case for not rebuilding it as code at all. On CodeWords you describe what the automation should do in plain language and Cody, the automation builder, builds it, with model access provided rather than requiring your own keys and quota management. Automations connect to more than 3,000 integrations. The free plan covers light use, with Pro at $39 per month and Business at $100 per month as usage grows; details are on the pricing page.

The errors you will hit while migrating

Five account for nearly every support question during a PaLM migration, and each has a specific cause.

"Model not found" on a model you know exists. Usually a PaLM identifier that survived the search, or a model not available in your region or to your account type. Listing available models through the API settles it in a moment.

A 400 complaining about the request body. Almost always a prompt still being sent as a plain string rather than wrapped in the contents array structure. This is the single most common migration error and the fix is mechanical.

An empty response with no error. A safety filter blocked it. Check the block reason on the response rather than treating it as a failure of the request. Code that assumes a successful status means usable content will behave strangely here.

Output that stops mid-sentence. The output token limit was reached. Check the finish reason, and either raise the limit or break the generation into sections.

Embeddings failing after everything else works. The embedding models were renamed along with everything else, and embedding-gecko no longer exists. Embeddings tend to live in a different part of the codebase from generation, which is why they are found last.

A worthwhile habit during the migration is logging the full response object rather than just the text on the first few calls, including the finish reason, the safety ratings, and the usage metadata. Nearly all of these announce themselves clearly in fields that a convenience wrapper would hide from you, and once you have seen each one a second time they become obvious immediately.

Where Gemini fits against other models

Honest positioning rather than a scoreboard, since benchmarks move constantly and rarely predict how a model behaves on your particular work.

Gemini's distinctive strengths are the long context window, genuinely native multimodality, and pricing on the Flash tier that makes high-volume work affordable. The integration with Google's own services matters if your data already lives in Drive, Sheets, or BigQuery.

The practical advice is to test rather than to read comparisons. Take twenty real examples from your actual workload, run them through two or three candidate models, and look at the outputs yourself. This takes an afternoon and tells you more than any benchmark table, because it measures the thing you actually care about.

Frequently asked questions

Is the PaLM API still available?

No. The endpoints were shut down after deprecation, and requests to them fail. Any integration still naming text-bison or chat-bison needs migrating to Gemini.

Will my PaLM prompts work unchanged?

The prompt text generally transfers. The structure around it does not, since Gemini expects a contents array rather than a plain string. Expect to rewrite request construction and to re-test outputs, since behaviour differs even on identical prompts.

Which model should I start with?

A Flash model, for almost everything. It handles classification, extraction, and summarization well at low cost and latency. Move individual cases to Pro where measurement shows Flash is not good enough, rather than starting there by default.

Why am I getting empty responses?

Most often a safety filter blocked the response. Check for a block reason in the response rather than assuming an error. Adjusting the safety thresholds is possible where your use case warrants it and your account permits.

Does the long context window mean I can stop chunking?

For documents that fit, yes, and this simplifies a great deal. You still pay per token, so sending a very long context on every request of a high-volume workflow is expensive. Context caching is the answer where the same large context is reused.

Can I use Gemini without writing code?

Google AI Studio provides an interface for experimenting without an integration, which is the right place to test prompts. For running something on a schedule or a trigger, an automation platform handles the model access and the plumbing without an application to maintain.

How do structured outputs differ from just asking for JSON?

Supplying a response schema constrains the generation so the output conforms, rather than asking politely and parsing whatever arrives. It removes the class of failure where a model returns valid-looking JSON wrapped in explanatory prose.

Get started today

Your first workflow is free to build.

Describe what you need. Cody handles the build, the connections, and the deployment.