Skip to content
Open
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
9 changes: 5 additions & 4 deletions integrations/llms/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const response = await portkey.chat.completions.create({
console.log(response.choices[0].message.content)
```

```python OpenAI Py icon="openai"
```python OpenAI Py icon="python"
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL

Expand All @@ -85,7 +85,7 @@ response = client.chat.completions.create(
print(response.choices[0].message.content)
```

```js OpenAI JS icon="openai"
```js OpenAI JS icon="square-js"
import OpenAI from "openai"
import { PORTKEY_GATEWAY_URL } from "portkey-ai"

Expand Down Expand Up @@ -380,7 +380,7 @@ portkey = Portkey(api_key="PORTKEY_API_KEY")

# Fetch and encode the PDF
pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
pdf_data = base64.standard_b64encode(httpx.get(pdf_url).content).decode("utf-8")
pdf_data = "data:application/pdf;base64," + base64.standard_b64encode(httpx.get(pdf_url).content).decode("utf-8")

response = portkey.chat.completions.create(
model="@anthropic/claude-sonnet-4-5-20250929",
Expand Down Expand Up @@ -412,6 +412,7 @@ const portkey = new Portkey({
const pdfUrl = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
const pdfResponse = await axios.get(pdfUrl, { responseType: 'arraybuffer' })
const pdfBase64 = Buffer.from(pdfResponse.data).toString('base64')
const pdfData = `data:application/pdf;base64,${pdfBase64}`

const response = await portkey.chat.completions.create({
model: "@anthropic/claude-sonnet-4-5-20250929",
Expand All @@ -422,7 +423,7 @@ const response = await portkey.chat.completions.create({
role: "user",
content: [
{ type: "text", text: "What are the key findings in this document?" },
{ type: "file", file: { mime_type: "application/pdf", file_data: pdfBase64 } }
{ type: "file", file: { mime_type: "application/pdf", file_data: pdfData } }
]
}
]
Expand Down
Loading