Skip to Content
PurAI is SHUT DOWN. This website is purely for archival purposes. No such services exist anymore.

Using Google Gemini Chat Completion

Google’s Gemini models are available through the same OpenAI-compatible request shape as the other chat completion endpoints, so switching between providers only requires changing the URL and model name.

Personalities and built-in functions are features of the OpenAI endpoint and are not available here.

Request

URL: https://ai.purlabs.xyz/google/chat/completions

Request Method: POST

TS Interface

interface Request { model: string; messages: { role: 'system' | 'user' | 'assistant'; content: string; }[]; temperature?: number; top_p?: number; top_k?: number; max_tokens?: number; stop?: string | string[] | null; };

Request API Reference

ParameterType (check TS Interface)RequiredDescription
modelstringRequiredThe model to use, such as gemini-pro. Refer to the Listing Available Models page for more information.
messagesobject[]RequiredThe list of messages in the conversation so far.
messages.rolestringRequiredThe author of the message: system, user, or assistant.
messages.contentstringRequiredThe text content of the message.
temperaturenumberOptionalThe sampling temperature, between 0 and 1. Higher values make the output more random; lower values make it more focused and deterministic.
top_pnumberOptionalNucleus sampling: the model considers tokens comprising the top top_p probability mass.
top_knumberOptionalThe model considers only the top_k most likely tokens at each step.
max_tokensnumberOptionalThe maximum number of tokens to generate in the response.
stopstring | string[] | nullOptionalUp to four sequences where the model will stop generating further tokens.

Example JSON Request Body

{ "model": "gemini-pro", "messages": [ { "role": "user", "content": "Summarize the benefits of unit testing in two sentences." } ] }

Response

TS Response Interface

interface Response { id: string; object: 'chat.completion'; created: number; model: string; choices: [ { index: number; message: { role: 'assistant', content: string; }; finish_reason: any; } ]; overwritten: boolean; provider: string; };

Example JSON Response

{ "id": "f81d4fae7dec11d0a76500a0c91e6bf6", "object": "chat.completion", "created": 1703031002, "model": "gemini-pro", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Unit testing catches defects early by verifying that each piece of code behaves as expected in isolation, which makes bugs cheaper and faster to fix. It also serves as living documentation and gives developers the confidence to refactor code without breaking existing functionality." }, "finish_reason": "stop" } ], "provider": "provider-1", "overwritten": false }
Last updated on