Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/content/docs/ai-gateway/providers/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic`

## Examples

### cURL

```bash title="Example fetch request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1/messages \
--header 'x-api-key: {anthropic_api_key}' \
Expand All @@ -27,6 +29,8 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic/v1
}'
```

### Use Anthropic SDK with JavaScript

If you are using the `@anthropic-ai/sdk`, you can set your endpoint like this:

```js title="JavaScript"
Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/ai-gateway/providers/azureopenai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Your new base URL will use the data above in this structure: `https://gateway.ai

## Examples

### cURL

```bash title="Example fetch request"
curl 'https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}/chat/completions?api-version=2023-05-15' \
--header 'Content-Type: application/json' \
Expand All @@ -41,6 +43,8 @@ curl 'https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-opena
}'
```

### Use `openai-node` with JavaScript

If you are using the `openai-node` library, you can set your endpoint like this:

```js title="JavaScript"
Expand Down
4 changes: 3 additions & 1 deletion src/content/docs/ai-gateway/providers/bedrock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ When making requests to Amazon Bedrock, replace `https://bedrock-runtime.us-east

With Bedrock, you will need to sign the URL before you make requests to AI Gateway. You can try using the [`aws4fetch`](https://github.com/mhart/aws4fetch) SDK.

## Example:
## Examples

### Use `aws4fetch1` SDK with TypeScript

```typescript
import { AwsClient } from "aws4fetch";
Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/ai-gateway/providers/cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ When making requests to [Cohere](https://cohere.com/), replace `https://api.cohe

## Examples

### cURL

```bash title="Request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1/chat \
--header 'Authorization: Token {cohere_api_token}' \
Expand All @@ -31,6 +33,8 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1/ch
}'
```

### Use Cohere SDK with Python

If using the [`cohere-python-sdk`](https://github.com/cohere-ai/cohere-python), set your endpoint like this:

```js title="Python"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai
}'
```

### JavaScript
### Use `@google/generative-ai` with JavaScript

If you are using the `@google/generative-ai` package, you can set your endpoint like this:

Expand Down
8 changes: 8 additions & 0 deletions src/content/docs/ai-gateway/providers/grok.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok/v1/chat
}'
```

### Use OpenAI SDK with JavaScript

If you are using the OpenAI SDK with JavaScript, you can set your endpoint like this:

```js title="JavaScript"
Expand Down Expand Up @@ -66,6 +68,8 @@ const completion = await openai.chat.completions.create({
console.log(completion.choices[0].message);
```

### Use OpenAI SDK with Python

If you are using the OpenAI SDK with Python, you can set your endpoint like this:

```python title="Python"
Expand All @@ -89,6 +93,8 @@ completion = client.chat.completions.create(
print(completion.choices[0].message)
```

### Use Anthropic SDK with JavaScript

If you are using the Anthropic SDK with JavaScript, you can set your endpoint like this:

```js title="JavaScript"
Expand Down Expand Up @@ -116,6 +122,8 @@ const msg = await anthropic.messages.create({
console.log(msg);
```

### Use Anthropic SDK with Python

If you are using the Anthropic SDK with Python, you can set your endpoint like this:

```python title="Python"
Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/ai-gateway/providers/groq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ When making requests to [Groq](https://groq.com/), replace `https://api.groq.com

## Examples

### cURL

```bash title="Example fetch request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq/chat/completions \
--header 'Authorization: Bearer {groq_api_key}' \
Expand All @@ -32,6 +34,8 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq/chat/co
}'
```

### Use Groq SDK with JavaScript

If using the [`groq-sdk`](https://www.npmjs.com/package/groq-sdk), set your endpoint like this:

```js title="JavaScript"
Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/ai-gateway/providers/huggingface.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ When making requests to HuggingFace Inference API, replace `https://api-inferenc

## Examples

### cURL

```bash title="Request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface/bigcode/starcoder \
--header 'Authorization: Bearer {hf_api_token}' \
Expand All @@ -26,6 +28,8 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface/
}'
```

### Use HuggingFace.js library with JavaScript

If you are using the HuggingFace.js library, you can set your inference endpoint like this:

```js title="JavaScript"
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/ai-gateway/providers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pcx_content_type: navigation
title: Model providers
sidebar:
group:
hideIndex: true
order: 3
---

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/ai-gateway/providers/mistral.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mist
}'
```

### JavaScript
### Use `@mistralai/mistralai` package with JavaScript

If you are using the `@mistralai/mistralai` package, you can set your endpoint like this:

Expand Down
66 changes: 66 additions & 0 deletions src/content/docs/ai-gateway/providers/open-router.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: OpenRouter
pcx_content_type: get-started
sidebar:
badge:
text: Beta
---

[OpenRouter](https://openrouter.ai/) is a platform that provides a unified interface for accessing and using large language models (LLMs).

## Endpoint

```txt
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter
```

## URL structure

When making requests to [OpenRouter](https://openrouter.ai/), replace `https://openrouter.ai/api/v1/chat/completions` in the URL you are currently using with `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter`.

## Examples

### cURL

```bash title="Request"
curl -X POST https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openrouter/v1/chat/completions \
--header 'content-type: application/json' \
--header 'Authorization: Bearer OPENROUTER_TOKEN' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--header 'Authorization: Bearer OPENROUTER_TOKEN' \
--header 'Authorization: Bearer <OPENROUTER_TOKEN>' \

--data '{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"model": "openai/gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'

```

### Use OpenAI SDK with JavaScript

If you are using the OpenAI SDK with JavaScript, you can set your endpoint like this:

```js title="JavaScript"
import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: env.OPENROUTER_TOKEN,
baseURL: "https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openrouter"
});

try {
const chatCompletion = await openai.chat.completions.create({
model: "openai/gpt-3.5-turbo",
messages: [{ role: "user", content: "What is Cloudflare?" }]
});

const response = chatCompletion.choices[0].message;

return new Response(JSON.stringify(response));
} catch (e) {
return new Response(e);
}

```
6 changes: 5 additions & 1 deletion src/content/docs/ai-gateway/providers/openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ When making requests to OpenAI, replace `https://api.openai.com/v1` in the URL y

## Examples

### cURL

```bash title="Request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer {openai_token}' \
Expand All @@ -33,7 +35,9 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/
'
```

If you’re using a library like openai-node, set the `baseURL` to your OpenAI endpoint like this:
### Use OpenAI SDK with JavaScript

If you are using a library like openai-node, set the `baseURL` to your OpenAI endpoint like this:

```js title="JavaScript"
import OpenAI from "openai";
Expand Down
6 changes: 5 additions & 1 deletion src/content/docs/ai-gateway/providers/perplexity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-ai

## Examples

### cURL

```bash title="Example fetch request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-ai/chat/completions \
--header 'accept: application/json' \
Expand All @@ -29,7 +31,9 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/perplexity-a
}'
```

Perplexity doesn't have their own SDK, but they have compatibility with the OpenAI SDK. You can use the OpenAI SDK to make a Perplexity call through AI Gateway as follows:
### Use Perplexity through OpenAI SDK with JavaScript

Perplexity does not have their own SDK, but they have compatibility with the OpenAI SDK. You can use the OpenAI SDK to make a Perplexity call through AI Gateway as follows:

```js title="JavaScript"
import OpenAI from "openai";
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/ai-gateway/providers/replicate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ When making requests to Replicate, replace `https://api.replicate.com/v1` in the

## Example

### cURL

```bash title="Request"
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/replicate/predictions \
--header 'Authorization: Token {replicate_api_token}' \
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/ai-gateway/providers/vertex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ So your final URL will come together as: `https://gateway.ai.cloudflare.com/v1/{

## Example

### cURL

```bash title="Example fetch request"
curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-vertex-ai/v1/projects/{project_name}/locations/{region}/publishers/google/models/gemini-1.0-pro-001:generateContent" \
-H "Authorization: Bearer {vertex_api_key}" \
Expand Down
Loading