AI Services Integration

Forge provides seamless integration with leading AI services and platforms through Forge Ignite, your secure backend proxy. Since Forge sites are static, all AI service calls should go through Ignite Cloud Code — keeping your API keys safe on the server and never exposing them in browser code.

This guide covers how to integrate popular AI services like OpenAI, Google AI, Azure Cognitive Services, and custom AI models into your Forge applications using Ignite.

Supported AI Services

OpenAI

Integrate GPT models for text generation, conversation, and content creation. OpenAI's powerful language models can enhance your applications with natural language processing capabilities.

  • GPT-3.5 and GPT-4 models
  • Text generation and completion
  • Conversational AI and chatbots
  • Content summarization and analysis
  • Code generation and assistance

Google AI

Leverage Google's machine learning and AI services for natural language processing, computer vision, and predictive analytics.

  • Natural Language Processing (NLP)
  • Computer Vision and Image Analysis
  • Translation and Language Detection
  • Speech-to-Text and Text-to-Speech
  • Predictive Analytics

Azure Cognitive Services

Microsoft's comprehensive AI platform offering a wide range of cognitive services for building intelligent applications.

  • Language Understanding (LUIS)
  • Computer Vision and Face Recognition
  • Speech Services
  • Knowledge Mining
  • Decision Services

Custom AI Models

Deploy and integrate your own trained AI models for specialized use cases and domain-specific applications.

  • Custom machine learning models
  • Domain-specific AI solutions
  • Proprietary algorithms
  • Specialized NLP models
  • Industry-specific AI applications

Integration Setup

OpenAI Integration

Set up OpenAI integration through Forge Ignite:

  1. Sign up for an OpenAI account and obtain API keys
  2. Add your OpenAI API key to Forge Ignite environment variables (never in your site code)
  3. Create an Ignite Cloud Code function to proxy requests
  4. Implement error handling and rate limiting in Cloud Code
  5. Call your Ignite endpoint from the frontend

Forge Ignite Cloud Code (server-side):

const OpenAI = require('openai');

const openai = new OpenAI({
    apiKey: process.env.OPENAIAPIKEY
});

Parse.Cloud.define('generateText', async (request) => {
    const { prompt } = request.params;
    try {
        const completion = await openai.chat.completions.create({
            model: 'gpt-4',
            messages: [{ role: 'user', content: prompt }]
        });
        return completion.choices[0].message.content;
    } catch (error) {
        console.error('OpenAI API error:', error);
        throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'AI service error');
    }
});

Frontend code:

async function generateText(prompt) {
    const result = await Parse.Cloud.run('generateText', { prompt });
    document.getElementById('output').textContent = result;
}

Google AI Integration

Integrate Google AI services through Forge Ignite:

  1. Set up a Google Cloud project and enable AI services
  2. Create service account credentials
  3. Add credentials to Forge Ignite environment variables
  4. Create Ignite Cloud Code functions for each AI capability

Forge Ignite Cloud Code (server-side):

const language = require('@google-cloud/language');

const client = new language.LanguageServiceClient({
    keyFilename: process.env.GOOGLEAPPLICATIONCREDENTIALS
});

Parse.Cloud.define('analyzeSentiment', async (request) => {
    const { text } = request.params;
    const document = { content: text, type: 'PLAIN_TEXT' };
    const [result] = await client.analyzeSentiment({ document });
    return result.documentSentiment;
});

Azure Cognitive Services Integration

Set up Azure Cognitive Services through Forge Ignite:

  1. Create an Azure account and deploy Cognitive Services resources
  2. Obtain API keys and endpoints
  3. Add credentials to Forge Ignite environment variables
  4. Create Ignite Cloud Code functions to proxy requests

Forge Ignite Cloud Code (server-side):

const ComputerVisionClient = require('@azure/cognitiveservices-computervision').ComputerVisionClient;
const ApiKeyCredentials = require('@azure/ms-rest-js').ApiKeyCredentials;

const computerVisionClient = new ComputerVisionClient(
    new ApiKeyCredentials({
        inHeader: { 'Ocp-Apim-Subscription-Key': process.env.AZUREVISIONKEY }
    }),
    process.env.AZUREVISIONENDPOINT
);

Parse.Cloud.define('analyzeImage', async (request) => {
    const { imageUrl } = request.params;
    const result = await computerVisionClient.analyzeImage(imageUrl, {
        visualFeatures: ['Categories', 'Description', 'Color']
    });
    return result;
});

Best Practices

API Key Security

Secure your AI service credentials:

  • Always store API keys in Forge Ignite environment variables — never in your Forge site code
  • Forge sites are static; any secrets in client-side code are visible to anyone inspecting the page
  • Use different API keys for staging and production Ignite environments
  • Rotate keys regularly
  • Monitor API usage and costs through your service provider dashboard
  • Implement rate limiting in your Ignite Cloud Code

Error Handling

Handle AI service errors gracefully:

  • Implement retry logic for transient failures
  • Provide fallback responses
  • Log errors for debugging
  • Show user-friendly error messages
  • Monitor service availability

Performance Optimization

Optimize your AI integrations:

  • Cache AI responses when appropriate
  • Use async/await for non-blocking operations
  • Implement request batching
  • Monitor response times
  • Optimize prompt engineering

Use Cases and Examples

Content Generation

Generate dynamic content using AI:

  • Blog post generation
  • Product descriptions
  • Email marketing content
  • Social media posts
  • Code documentation

User Experience Enhancement

Improve user experience with AI:

  • Intelligent search and recommendations
  • Personalized content delivery
  • AI-powered chatbots
  • Smart form validation
  • Predictive user interface

Data Analysis

Analyze data with AI capabilities:

  • Sentiment analysis
  • Text classification
  • Image recognition
  • Trend prediction
  • Anomaly detection

Monitoring and Analytics

Performance Monitoring

Monitor your AI integrations:

  • Track API response times
  • Monitor error rates
  • Analyze usage patterns
  • Measure user satisfaction
  • Track cost optimization

Analytics and Insights

Gain insights from AI usage:

  • User interaction patterns
  • Content performance metrics
  • AI feature adoption rates
  • Cost analysis and optimization
  • Quality metrics and feedback

Remember: Always route AI service calls through Forge Ignite — never call AI APIs directly from your frontend code. Test integrations thoroughly in your staging Ignite environment before deploying to production. Monitor costs and usage to ensure optimal performance and cost-effectiveness.

Ask AI About This Page

Get AI-powered answers about this topic. Ask any of these models with full context about Forge documentation to help you understand concepts, troubleshoot issues, and find related resources.

Ask Forge AI

Join the Discussion

Have questions or want to share your experience? Join our community discussion to connect with other developers and get help from the Forge team.

Visit Forum Discussion