Get started
AI observability
- Overview
- Getting started
- Metrics
- Logging
- Tracing
- Threads
- User analytics
- Advanced
Prompt engineering
- Overview
- Prompt management
- Prompt Playground
Evaluations
- Overview
- Experiments
- LLM evals
- Human evals
AI gateway
Organization management
Resources
AI gateway
Image upload
Learn how to upload image variables through Keywords AI gateway.
If you’re using the Keywords AI gateway, you can upload images to the LLM request.
We support base64
or url
format for image variables.
Upload image variables
Copy
from openai import OpenAI
client = OpenAI(
base_url="https://api.keywordsai.co/api/",
api_key="YOUR_KEYWORDSAI_API_KEY",
)
response = client.chat.completions.create(
model="gpt-4o-mini", # any model that supports image variables
messages=[{"role":"user", "content":"Tell me a long story"}],
extra_body={
"variables": {
"image_variable": {"_type": "image_url", "value": "url_string"}
}
},
)
Copy
from openai import OpenAI
client = OpenAI(
base_url="https://api.keywordsai.co/api/",
api_key="YOUR_KEYWORDSAI_API_KEY",
)
response = client.chat.completions.create(
model="gpt-4o-mini", # any model that supports image variables
messages=[{"role":"user", "content":"Tell me a long story"}],
extra_body={
"variables": {
"image_variable": {"_type": "image_url", "value": "url_string"}
}
},
)
Copy
import requests
def demo_call(input,
model="gpt-4o-mini", # also try "claude-3-5-sonnet-20240620"
token="YOUR_KEYWORDS_AI_API_KEY"
):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}',
}
data = {
'model': model,
'messages': [{'role': 'user', 'content': input}],
'variables': {
'image_variable': {'_type': 'image_url', 'value': 'url_string'}
}
}
response = requests.post('https://api.keywordsai.co/api/chat/completions', headers=headers, json=data)
return response
messages = "Say 'Hello World'"
print(demo_call(messages).json())
On this page
Assistant
Responses are generated using AI and may contain mistakes.