Reference API
Reference API
## Provider Endpoints
Groq: api.groq.com/openai
Hyperbolic: https://api.hyperbolic.xyz/v1
Mistral: api.mistral.ai
OpenAI: api.openai.com
OpenRouter: openrouter.ai/api
Together: api.together.xyz
xAI: https://api.x.ai/v1
Cerebras: https://api.cerebras.ai/v1
SambaNova: https://api.sambanova.ai/v1
FIreworks: https://api.fireworks.ai/inference/v1
Gemini: https://generativelanguage.googleapis.com/v1beta/openai
# Example Code
## Basic
```python
import requests, time
Keys = {
'mistral':'abc',
'openrouter':'sk-or-v1-abc',
'groq':'abc',
'openai': 'sk-abc'}
Endpoints = {
'mistral': 'https://api.mistral.ai/v1',
'openrouter': 'https://openrouter.ai/api/v1',
'groq': 'https://api.groq.com/openai/v1',
'openai': 'https://api.openai.com/v1'}
```python
import requests, json, sys
APIKey = "sk-or-v1-abc"
URL = "https://openrouter.ai/api/v1" + "/chat/completions"
model = "anthropic/claude-3.5-sonnet"
headers = {'Authorization': f"Bearer {APIKey}", 'Content-Type': 'application/json'}
data = {'model':model, 'stream': True, 'messages': [{'role': 'user', 'content': '''
Can you write a Python script to go through an arbitrary file, find all closed XML
blocks like `<obj type="c">...</obj>`, turn them all into dictionaries like
`{"tag": "obj", "type": "c"}`, and then give each dictionary a 'parent' pointer and
'children' list of pointers to the others in a way that represents the tree
structure of tag inclusions?
Making the dictionaries should be straightforward, but for formatting them into a
tree, I think you can do the following:
go through all the block <starts> and </ends> in order and construct a stack S:
when you encounter the nth opening <t_n>, initialize its dictionary D_n, do
D_n.parent = S.head and S.children.append(D_n), and then S.push(D_n);
whenever you encounter a closing </t>, assert t == S.head.tag (since otherwise the
XML is misformatted, right?) and then S.pop().
If this seems right, can you go ahead and implement it?
'''.strip()}]}
response = requests.post(URL, headers=headers, json=data, stream=True).iter_lines()
for chunk in response:
if chunk and b'data: {' in chunk:
print(json.loads(chunk[6:])['choices'][0]['delta']['content'], end='')
print()
```
## Groq
```python
import requests
APIKey = "abc"
URL = "https://api.groq.com/openai/v1" + "/chat/completions"
Model = "llama3-70b-8192"
# Misc.