# API Guide

Understand how to use Aivara APIs and seamlessly integrate with AI providers like OpenAI, Claude, Gemini, and more to power your workflows.

Aivara offers a unified API to simplify the development of AI workflows and agents. This guide explains how to:

1. **Use** Aivara **APIs** to manage workflows and agents.
2. **Integrate External APIs** from AI providers like OpenAI, Anthropic, Google, and more.

***

**1.** Aivara **API**

The Aivara API is your starting point for building and managing workflows.

**Base URL**

Copy

Copy

Copy

```
plaintextCopy codehttps://api.aivara.dev/v1/
```

**Authentication**

Include your Aivara **API Key** in the header:

Copy

Copy

Copy

```
httpCopy codeAuthorization: Bearer YOUR_AIVARA_API_KEY
```

**Example: Create an AI Workflow**

Copy

Copy

Copy

```
httpCopy codePOST /workflows
Host: api.aivara.dev
Authorization: Bearer YOUR_AIVARA_API_KEY
Content-Type: application/json

{
  "name": "example-workflow",
  "input": { "platform": "discord", "parameters": { "token": "YOUR_DISCORD_TOKEN" }},
  "processing": { "provider": "openai", "model": "gpt-4", "api_key": "YOUR_OPENAI_KEY" },
  "output": { "platform": "discord" }
}
```

***

**2. External API Providers**

Aivara integrates seamlessly with external AI providers via their APIs. Here’s a breakdown of key providers and usage:

***

**OpenAI API**

**Base URL**:

Copy

Copy

Copy

```
plaintextCopy codehttps://api.openai.com/v1/
```

**Authentication**: Use your OpenAI API Key in the header:

Copy

Copy

Copy

```
httpCopy codeAuthorization: Bearer YOUR_OPENAI_API_KEY
```

**Request Example: Generating Text with GPT-4**

Copy

Copy

Copy

```
httpCopy codePOST /chat/completions
Host: api.openai.com
Authorization: Bearer YOUR_OPENAI_API_KEY
Content-Type: application/json

{
  "model": "gpt-4",
  "messages": [{"role": "user", "content": "Tell me about Aivara."}],
  "max_tokens": 100
}
```

**Response Example**:

Copy

Copy

Copy

```
jsonCopy code{
  "id": "chatcmpl-abc123",
  "choices": [{"message": {"role": "assistant", "content": "Aivara is a full-stack AI library."}}],
  "usage": {"total_tokens": 50}
}
```

***

**Anthropic Claude API**

**Base URL**:

Copy

Copy

Copy

```
plaintextCopy codehttps://api.anthropic.com/v1/
```

**Authentication**: Use your Claude API Key in the `x-api-key` header:

Copy

Copy

Copy

```
httpCopy codex-api-key: YOUR_ANTHROPIC_API_KEY
```

**Request Example**:

Copy

Copy

Copy

```
httpCopy codePOST /messages
Host: api.anthropic.com
x-api-key: YOUR_ANTHROPIC_API_KEY
Content-Type: application/json

{
  "model": "claude-2",
  "messages": [{"role": "user", "content": "What is Aivara?"}],
  "max_tokens": 100
}
```

***

**Google Gemini API**

**Base URL**:

Copy

Copy

Copy

```
plaintextCopy codehttps://generativelanguage.googleapis.com/v1/
```

**Authentication**: Pass the API key in the URL:

Copy

Copy

Copy

```
httpCopy code?key=YOUR_GEMINI_API_KEY
```

**Request Example: Generating Text**

Copy

Copy

Copy

```
httpCopy codePOST /models/gemini-1:generateContent
Content-Type: application/json

{
  "contents": [{"parts": [{"text": "Explain how Aivara works."}]}]
}
```

***

**3. Combining Providers with Aivara**

Aivara’s modular blocks allow you to seamlessly combine these APIs. For example:

**Workflow Example**: Sending a query to Claude and using the response to post on Discord.

Copy

Copy

Copy

```
pythonCopy codefrom aivara import InputBlock, ProcessingBlock, OutputBlock

# Input: Fetch user query
input_block = InputBlock("discord", token="DISCORD_TOKEN")

# Processing: Send to Claude API
processing_block = ProcessingBlock("claude", model="claude-2", api_key="CLAUDE_API_KEY")

# Output: Post response back to Discord
output_block = OutputBlock("discord_response", token="DISCORD_TOKEN")

# Run workflow
workflow = input_block >> processing_block >> output_block
workflow.run()
```

***

**4. Key Benefits of Using** Aivara **with APIs**

* **Unified Management**: Handle multiple AI provider APIs through Aivara workflows.
* **Ease of Use**: No need to write complex API integrations—Aivara simplifies everything.
* **Flexibility**: Use providers like OpenAI, Claude, and Gemini based on your project needs.
* **Scalability**: Deploy workflows seamlessly across platforms like Discord, Telegram, and Twitter.

***

**Conclusion**

Aivara acts as the central hub for managing your AI workflows while integrating effortlessly with external APIs. Whether you’re using OpenAI for text generation, Claude for reasoning, or Gemini for multimodal tasks, Aivara makes development faster and simpler.

Start building today with Aivara and your favorite AI providers.
