Hey I would love to contribute to SpringAI to make Gemini directly accessible to the Java server side world. However I could not find an OpenAPI spec and I would love to not have to reverse engineer existing SDKs.
Perhaps I should jump into that thread. But a few notes:
The REST API for the Vertex AI Gemini API and AI Studio Gemini API are nearly identical.
There are subtle differences, but they’re subtle. So you may be able to start with the Vertex AI implementation that Spring AI already supports.
The biggest difference is the auth method, but providing an API key instead of going through Google Auth isn’t difficult. (And the AI Studio API also takes Google Auth.)
The other big difference is the endpoint. This shouldn’t be that big a deal at all.
I’m the primary author of the @langchain/google-common package for node.js which provides Gemini API support for both Vertex AI and AI Studio out of a single package. So it can be done. It may help for you to read the Typescript definitions for GeminiRequest and GenerateContentResponseData which represent most of the REST format.
I’ll try to take a look at the Spring AI Gemini support, but I’ve got a lot on my plate right now catching up with LangChain.js now that the competition is done. But please feel free to reach out to me directly or on this thread to discuss.
Hi, thanks for this, however it seems there are some discripency on this openAPI compare to the API reference
For example
Indicates there’s no “model” field for GenerateContentRequest
However, in the OpenAPI discovery it shows “model” is a required field
"GenerateContentRequest": {
"type": "object",
"description": "Request to generate a completion from the model.\nNEXT ID: 14",
"required": [
"model",
"contents"
],
"properties": {
"systemInstruction": {
"allOf": [
{
"$ref": "#/components/schemas/Content"
}
],
"description": "Optional. Developer set [system\ninstruction(s)](https://ai.google.dev/gemini-api/docs/system-instructions).\nCurrently, text only."
},
"cachedContent": {
"type": "string",
"description": "Optional. The name of the content\n[cached](https://ai.google.dev/gemini-api/docs/caching) to use as context\nto serve the prediction. Format: `cachedContents/{cachedContent}`"
},
"tools": {
"type": "array",
"description": "Optional. A list of `Tools` the `Model` may use to generate the next response.\n\nA `Tool` is a piece of code that enables the system to interact with\nexternal systems to perform an action, or set of actions, outside of\nknowledge and scope of the `Model`. Supported `Tool`s are `Function` and\n`code_execution`. Refer to the [Function\ncalling](https://ai.google.dev/gemini-api/docs/function-calling) and the\n[Code execution](https://ai.google.dev/gemini-api/docs/code-execution)\nguides to learn more.",
"items": {
"$ref": "#/components/schemas/Tool"
}
},
"model": {
"description": "Required. The name of the `Model` to use for generating the completion.\n\nFormat: `models/{model}`.",
"type": "string"
},
...