Proxy Integration
- VertexAI Python
- VertexAI JS
- Fetch
1
2
Set API keys as environment variables
Copy
export QUALIFIRE_API_KEY=<your API key>
3
Install necessary packages
Ensure you have the necessary packages installed in your Javascript project:
Copy
pip install --upgrade google-cloud-aiplatform
gcloud auth application-default login
4
Import VertexAI and configure the client
Copy
import vertexai
from vertexai.generative_models import GenerativeModel
LOCATION = "us-central1"
vertexai.init(
project="<PROJECT-ID>",
location="<LOCATION>",
api_transport="rest",
api_endpoint="https://proxy.qualifire.ai/api/providers/google",
request_metadata=[
("X-Qualifire-Base-Url", f"https://{LOCATION}-aiplatform.googleapis.com"),
("X-Qualifire-API-Key", "<your API key>"),
],
)
model = GenerativeModel(
"gemini-1.5-flash-002",
)
5
Call the API
Copy
def generate():
responses = model.generate_content(
["""tell me a joke about cats"""],
generation_config=generation_config,
stream=True,
)
for response in responses:
print(response.text, end="")
generation_config = {
"max_output_tokens": 8192,
"temperature": 1,
"top_p": 0.95,
}
generate()
VertexAI SDK
1
2
Set API keys as environment variables
Copy
export QUALIFIRE_API_KEY=<your API key>
export GCLOUD_API_KEY=<your Google Cloud API key>
3
Install necessary packages
Ensure you have the necessary packages installed in your Javascript project:
Copy
npm install @google-cloud/vertexai
4
Import VertexAI and configure the client
Copy
import { VertexAI } from "@google-cloud/vertexai";
const vertex_ai = new VertexAI({
project: "your-project-id",
location: "your-location",
apiEndpoint: "proxy.qualifire.ai",
});
5
Set up custom headers
Copy
const customHeaders = new Headers({
"X-Qualifire-Api-Key": `${process.env.QUALIFIRE_API_KEY}`,
"X-Qualifire-Target-URL": `https://${LOCATION}-aiplatform.googleapis.com`,
});
6
Call the API
Copy
const model = genAI.getGenerativeModel(
{
model: "model-name",
},
requestOptions
);
async function run() {
const prompt = "Write a story about a magic backpack.";
const result = await model.generateContent(prompt);
const response = result.response;
const text = await response.text();
console.log(text);
}
run();
Fetch
1
2
Set API keys as environment variables
Copy
export QUALIFIRE_API_KEY=<your API key>
export GCLOUD_API_KEY=<your Google Cloud API key>
3
Install necessary packages
Ensure you have the necessary packages installed in your Javascript project:
Copy
npm install node-fetch
4
Send a request using fetch
Copy
const fetch = require('node-fetch');
const url = 'https://proxy.qualifire.ai/api/providers/google/';
const headers = {
'Authorization': `Bearer ${process.env.GCLOUD_API_KEY}`,
'Content-Type': 'application/json',
'X-Qualifire-Api-Key': `${process.env.QUALIFIRE_API_KEY}`,
'X-Qualifire-Target-URL': `https://${LOCATION}-aiplatform.googleapis.com`,
'User-Agent': 'node-fetch'
};
const requestOptions = {
customHeaders: customHeaders,
baseUrl: "https://proxy.qualifire.ai/api/providers/google/",
} as RequestOptions;
5
Call the API
Copy
const url = "https://proxy.qualifire.ai/api/providers/google";
fetch(url, { method: 'POST', headers: headers, body: body })
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));